1 /* Copyright (c) 2012-2013, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
4 /* Formatting and parsing code for crypto-related data structures. */
11 #include "crypto_curve25519.h"
16 curve25519_public_to_base64(char *output
,
17 const curve25519_public_key_t
*pkey
)
20 base64_encode(buf
, sizeof(buf
),
21 (const char*)pkey
->public_key
, CURVE25519_PUBKEY_LEN
);
22 buf
[CURVE25519_BASE64_PADDED_LEN
] = '\0';
23 memcpy(output
, buf
, CURVE25519_BASE64_PADDED_LEN
+1);
28 curve25519_public_from_base64(curve25519_public_key_t
*pkey
,
31 size_t len
= strlen(input
);
32 if (len
== CURVE25519_BASE64_PADDED_LEN
- 1) {
34 return digest256_from_base64((char*)pkey
->public_key
, input
);
35 } else if (len
== CURVE25519_BASE64_PADDED_LEN
) {
37 if (base64_decode(buf
, sizeof(buf
), input
, len
) != CURVE25519_PUBKEY_LEN
)
39 memcpy(pkey
->public_key
, buf
, CURVE25519_PUBKEY_LEN
);