[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Make our ed25519 implementations no longer use openssl directly.
commit 38fb651f0d740bef575ad7f95475cc504ea4cb8f
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Sat Mar 25 11:49:41 2017 +0100
Make our ed25519 implementations no longer use openssl directly.
---
src/ext/ed25519/donna/ed25519-hash-custom.h | 31 +++++++++++++++++++++++++++++
src/ext/ed25519/ref10/crypto_hash_sha512.h | 30 +++++++++++++++-------------
src/ext/include.am | 1 +
3 files changed, 48 insertions(+), 14 deletions(-)
diff --git a/src/ext/ed25519/donna/ed25519-hash-custom.h b/src/ext/ed25519/donna/ed25519-hash-custom.h
index 7dc2491..609451a 100644
--- a/src/ext/ed25519/donna/ed25519-hash-custom.h
+++ b/src/ext/ed25519/donna/ed25519-hash-custom.h
@@ -9,3 +9,34 @@
void ed25519_hash(uint8_t *hash, const uint8_t *in, size_t inlen);
*/
+#include "crypto.h"
+
+typedef struct ed25519_hash_context {
+ crypto_digest_t *ctx;
+} ed25519_hash_context;
+
+
+static void
+ed25519_hash_init(ed25519_hash_context *ctx)
+{
+ ctx->ctx = crypto_digest512_new(DIGEST_SHA512);
+}
+static void
+ed25519_hash_update(ed25519_hash_context *ctx, const uint8_t *in, size_t inlen)
+{
+ crypto_digest_add_bytes(ctx->ctx, (const char *)in, inlen);
+}
+static void
+ed25519_hash_final(ed25519_hash_context *ctx, uint8_t *hash)
+{
+ crypto_digest_get_digest(ctx->ctx, (char *)hash, DIGEST512_LEN);
+ crypto_digest_free(ctx->ctx);
+ ctx->ctx = NULL;
+}
+static void
+ed25519_hash(uint8_t *hash, const uint8_t *in, size_t inlen)
+{
+ crypto_digest512((char *)hash, (const char *)in, inlen,
+ DIGEST_SHA512);
+}
+
diff --git a/src/ext/ed25519/ref10/crypto_hash_sha512.h b/src/ext/ed25519/ref10/crypto_hash_sha512.h
index 0278571..e454c4e 100644
--- a/src/ext/ed25519/ref10/crypto_hash_sha512.h
+++ b/src/ext/ed25519/ref10/crypto_hash_sha512.h
@@ -1,30 +1,32 @@
/* Added for Tor. */
-#include <openssl/sha.h>
+#include "crypto.h"
/* Set 'out' to the 512-bit SHA512 hash of the 'len'-byte string in 'inp' */
#define crypto_hash_sha512(out, inp, len) \
- SHA512((inp), (len), (out))
+ crypto_digest512((char *)(out), (const char *)(inp), (len), DIGEST_SHA512)
/* Set 'out' to the 512-bit SHA512 hash of the 'len1'-byte string in 'inp1',
* concatenated with the 'len2'-byte string in 'inp2'. */
#define crypto_hash_sha512_2(out, inp1, len1, inp2, len2) \
do { \
- SHA512_CTX sha_ctx_; \
- SHA512_Init(&sha_ctx_); \
- SHA512_Update(&sha_ctx_, (inp1), (len1)); \
- SHA512_Update(&sha_ctx_, (inp2), (len2)); \
- SHA512_Final((out), &sha_ctx_); \
- } while(0)
+ crypto_digest_t *sha_ctx_; \
+ sha_ctx_ = crypto_digest512_new(DIGEST_SHA512); \
+ crypto_digest_add_bytes(sha_ctx_, (const char *)(inp1), (len1)); \
+ crypto_digest_add_bytes(sha_ctx_, (const char *)(inp2), (len2)); \
+ crypto_digest_get_digest(sha_ctx_, (char *)out, 64); \
+ crypto_digest_free(sha_ctx_); \
+ } while (0)
/* Set 'out' to the 512-bit SHA512 hash of the 'len1'-byte string in 'inp1',
* concatenated with the 'len2'-byte string in 'inp2', concatenated with
* the 'len3'-byte string in 'len3'. */
#define crypto_hash_sha512_3(out, inp1, len1, inp2, len2, inp3, len3) \
do { \
- SHA512_CTX sha_ctx_; \
- SHA512_Init(&sha_ctx_); \
- SHA512_Update(&sha_ctx_, (inp1), (len1)); \
- SHA512_Update(&sha_ctx_, (inp2), (len2)); \
- SHA512_Update(&sha_ctx_, (inp3), (len3)); \
- SHA512_Final((out), &sha_ctx_); \
+ crypto_digest_t *sha_ctx_; \
+ sha_ctx_ = crypto_digest512_new(DIGEST_SHA512); \
+ crypto_digest_add_bytes(sha_ctx_, (const char *)(inp1), (len1)); \
+ crypto_digest_add_bytes(sha_ctx_, (const char *)(inp2), (len2)); \
+ crypto_digest_add_bytes(sha_ctx_, (const char *)(inp3), (len3)); \
+ crypto_digest_get_digest(sha_ctx_, (char *)out, 64); \
+ crypto_digest_free(sha_ctx_); \
} while(0)
diff --git a/src/ext/include.am b/src/ext/include.am
index c18e588..7ec2e43 100644
--- a/src/ext/include.am
+++ b/src/ext/include.am
@@ -101,6 +101,7 @@ noinst_LIBRARIES += $(LIBED25519_REF10)
src_ext_ed25519_donna_libed25519_donna_a_CFLAGS=\
@CFLAGS_CONSTTIME@ \
-DED25519_CUSTOMRANDOM \
+ -DED25519_CUSTOMHASH \
-DED25519_SUFFIX=_donna
src_ext_ed25519_donna_libed25519_donna_a_SOURCES= \
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits