summaryrefslogtreecommitdiffstats
path: root/include/libssh/ed25519.h
blob: 7b48856cca03836f6ae0799df7beebea3ca76a1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * This file is part of the SSH Library
 *
 * Copyright (c) 2014 by Aris Adamantiadis
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#ifndef ED25519_H_
#define ED25519_H_
#include "libssh/priv.h"

/**
 * @defgroup ed25519 ed25519 API
 * @internal
 * @brief API for DJB's ed25519
 *
 * @{ */

#define ED25519_PK_LEN 32
#define ED25519_SK_LEN 64
#define ED25519_SIG_LEN 64

typedef uint8_t ed25519_pubkey[ED25519_PK_LEN];
typedef uint8_t ed25519_privkey[ED25519_SK_LEN];
typedef uint8_t ed25519_signature[ED25519_SIG_LEN];

/** @internal
 * @brief generate an ed25519 key pair
 * @param[out] pk generated public key
 * @param[out] sk generated secret key
 * @return     0 on success, -1 on error.
 * */
int crypto_sign_ed25519_keypair(ed25519_pubkey pk, ed25519_privkey sk);

/** @internal
 * @brief sign a message with ed25519
 * @param[out] sm location to store the signed message.
 *                Its length should be mlen + 64.
 * @param[out] smlen pointer to the size of the signed message
 * @param[in] m message to be signed
 * @param[in] mlen length of the message to be signed
 * @param[in] sk secret key to sign the message with
 * @return    0 on success.
 */
int crypto_sign_ed25519(
    unsigned char *sm,unsigned long long *smlen,
    const unsigned char *m,unsigned long long mlen,
    const ed25519_privkey sk);

/** @internal
 * @brief "open" and verify the signature of a signed message
 * @param[out] m location to store the verified message.
 *               Its length should be equal to smlen.
 * @param[out] mlen pointer to the size of the verified message
 * @param[in] sm signed message to verify
 * @param[in] smlen length of the signed message to verify
 * @param[in] pk public key used to sign the message
 * @returns   0 on success (supposedly).
 */
int crypto_sign_ed25519_open(
    unsigned char *m,unsigned long long *mlen,
    const unsigned char *sm,unsigned long long smlen,
    const ed25519_pubkey pk);

/** @} */
#endif /* ED25519_H_ */