diff options
author | Nick Mathewson <nickm@torproject.org> | 2013-01-05 22:53:32 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2013-01-05 22:53:32 -0500 |
commit | 31d888c834b135d8f36ceec181f3d1ea7af62267 (patch) | |
tree | a1bbab98107d8a154875083e1b3c63be5b103e30 /src/common/crypto_curve25519.c | |
parent | dffc8e359bcfeb00813a3afde6aa2328f6a6a476 (diff) | |
download | tor-31d888c834b135d8f36ceec181f3d1ea7af62267.tar.gz tor-31d888c834b135d8f36ceec181f3d1ea7af62267.zip |
Make the = at the end of ntor-onion-key optional.
Makes bug 7869 more easily fixable if we ever choose to do so.
Diffstat (limited to 'src/common/crypto_curve25519.c')
-rw-r--r-- | src/common/crypto_curve25519.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/common/crypto_curve25519.c b/src/common/crypto_curve25519.c index a4ab65cf4f..aead4f8baa 100644 --- a/src/common/crypto_curve25519.c +++ b/src/common/crypto_curve25519.c @@ -178,3 +178,33 @@ curve25519_handshake(uint8_t *output, curve25519_impl(output, skey->secret_key, pkey->public_key); } +int +curve25519_public_to_base64(char *output, + const curve25519_public_key_t *pkey) +{ + char buf[128]; + base64_encode(buf, sizeof(buf), + (const char*)pkey->public_key, CURVE25519_PUBKEY_LEN); + buf[CURVE25519_BASE64_PADDED_LEN] = '\0'; + memcpy(output, buf, CURVE25519_BASE64_PADDED_LEN+1); + return 0; +} + +int +curve25519_public_from_base64(curve25519_public_key_t *pkey, + const char *input) +{ + size_t len = strlen(input); + if (len == CURVE25519_BASE64_PADDED_LEN - 1) { + /* not padded */ + return digest256_from_base64((char*)pkey->public_key, input); + } else if (len == CURVE25519_BASE64_PADDED_LEN) { + char buf[128]; + if (base64_decode(buf, sizeof(buf), input, len) != CURVE25519_PUBKEY_LEN) + return -1; + memcpy(pkey->public_key, buf, CURVE25519_PUBKEY_LEN); + return 0; + } else { + return -1; + } +} |