Browse Source

optimize stack arrays

* minimize stack usage
* no need to zero-initialize the arrays

Signed-off-by: Steffen Jaeckel <[email protected]>
Steffen Jaeckel 3 years ago
parent
commit
24275fee7e
2 changed files with 6 additions and 6 deletions
  1. 3 3
      src/pk/ed25519/ed25519_sign.c
  2. 3 3
      src/pk/ed25519/ed25519_verify.c

+ 3 - 3
src/pk/ed25519/ed25519_sign.c

@@ -67,7 +67,7 @@ int ed25519ctx_sign(const  unsigned char *msg, unsigned long  msglen,
                     const curve25519_key *private_key)
                     const curve25519_key *private_key)
 {
 {
    int err;
    int err;
-   unsigned char ctx_prefix[512] = {0};
+   unsigned char ctx_prefix[292];
    unsigned long ctx_prefix_size = sizeof(ctx_prefix);
    unsigned long ctx_prefix_size = sizeof(ctx_prefix);
 
 
    LTC_ARGCHK(ctx != NULL);
    LTC_ARGCHK(ctx != NULL);
@@ -94,8 +94,8 @@ int ed25519ph_sign(const  unsigned char *msg, unsigned long  msglen,
                    const curve25519_key *private_key)
                    const curve25519_key *private_key)
 {
 {
    int err;
    int err;
-   unsigned char ctx_prefix[512] = {0};
-   unsigned char msg_hash[64] = {0};
+   unsigned char msg_hash[64];
+   unsigned char ctx_prefix[292];
    unsigned long ctx_prefix_size = sizeof(ctx_prefix);
    unsigned long ctx_prefix_size = sizeof(ctx_prefix);
 
 
    if ((err = ec25519_crypto_ctx(ctx_prefix, &ctx_prefix_size, 1, ctx, ctxlen)) != CRYPT_OK)
    if ((err = ec25519_crypto_ctx(ctx_prefix, &ctx_prefix_size, 1, ctx, ctxlen)) != CRYPT_OK)

+ 3 - 3
src/pk/ed25519/ed25519_verify.c

@@ -70,7 +70,7 @@ int ed25519ctx_verify(const  unsigned char *msg, unsigned long msglen,
                                        int *stat,
                                        int *stat,
                       const curve25519_key *public_key)
                       const curve25519_key *public_key)
 {
 {
-   unsigned char ctx_prefix[512] = {0};
+   unsigned char ctx_prefix[292];
    unsigned long ctx_prefix_size = sizeof(ctx_prefix);
    unsigned long ctx_prefix_size = sizeof(ctx_prefix);
 
 
    LTC_ARGCHK(ctx != NULL);
    LTC_ARGCHK(ctx != NULL);
@@ -100,8 +100,8 @@ int ed25519ph_verify(const  unsigned char *msg, unsigned long msglen,
                      const curve25519_key *public_key)
                      const curve25519_key *public_key)
 {
 {
    int err;
    int err;
-   unsigned char ctx_prefix[512] = {0};
-   unsigned char msg_hash[64] = {0};
+   unsigned char msg_hash[64];
+   unsigned char ctx_prefix[292];
    unsigned long ctx_prefix_size = sizeof(ctx_prefix);
    unsigned long ctx_prefix_size = sizeof(ctx_prefix);
 
 
    if ((err = ec25519_crypto_ctx(ctx_prefix, &ctx_prefix_size, 1, ctx, ctxlen)) != CRYPT_OK)
    if ((err = ec25519_crypto_ctx(ctx_prefix, &ctx_prefix_size, 1, ctx, ctxlen)) != CRYPT_OK)