Skip to content

Commit 36e8935

Browse files
committed
Fix curve25519 in case sha512 is not available
Before this patch it silently didn't work, now it errors out. Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
1 parent 655d84c commit 36e8935

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

src/pk/ec25519/tweetnacl.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ int tweetnacl_crypto_sk_to_pk(u8 *pk, const u8 *sk)
312312
{
313313
u8 d[64];
314314
gf p[4];
315+
if (find_hash("sha512") == -1) return CRYPT_INVALID_HASH;
315316
tweetnacl_crypto_hash(d, sk, 32);
316317
d[0] &= 248;
317318
d[31] &= 127;
@@ -387,6 +388,8 @@ int tweetnacl_crypto_sign(u8 *sm,u64 *smlen,const u8 *m,u64 mlen,const u8 *sk,co
387388
i64 i,j,x[64];
388389
gf p[4];
389390

391+
if (find_hash("sha512") == -1) return CRYPT_INVALID_HASH;
392+
390393
tweetnacl_crypto_hash(d, sk, 32);
391394
d[0] &= 248;
392395
d[31] &= 127;
@@ -456,6 +459,7 @@ int tweetnacl_crypto_sign_open(int *stat, u8 *m,u64 *mlen,const u8 *sm,u64 smlen
456459
gf p[4],q[4];
457460

458461
*stat = 0;
462+
if (find_hash("sha512") == -1) return CRYPT_INVALID_HASH;
459463
if (*mlen < smlen) return CRYPT_BUFFER_OVERFLOW;
460464
*mlen = -1;
461465
if (smlen < 64) return CRYPT_INVALID_ARG;

src/pk/ed25519/ed25519_sign.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ static int s_ed25519_sign(const unsigned char *msg, unsigned long msglen,
2323
LTC_ARGCHK(siglen != NULL);
2424
LTC_ARGCHK(private_key != NULL);
2525

26+
if (find_hash("sha512") == -1) return CRYPT_INVALID_HASH;
2627
if (private_key->pka != LTC_PKA_ED25519) return CRYPT_PK_INVALID_TYPE;
2728
if (private_key->type != PK_PRIVATE) return CRYPT_PK_INVALID_TYPE;
2829

src/pk/ed25519/ed25519_verify.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ static int s_ed25519_verify(const unsigned char *msg, unsigned long msglen,
2626

2727
*stat = 0;
2828

29+
if (find_hash("sha512") == -1) return CRYPT_INVALID_HASH;
2930
if (siglen != 64uL) return CRYPT_INVALID_ARG;
3031
if (public_key->pka != LTC_PKA_ED25519) return CRYPT_PK_INVALID_TYPE;
3132

0 commit comments

Comments
 (0)