summaryrefslogtreecommitdiff
path: root/src/ext/ed25519/ref10/fe_frombytes.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2014-09-28 20:39:09 -0400
committerNick Mathewson <nickm@torproject.org>2014-09-28 20:41:05 -0400
commit6129ff320e6510a453922dba01163824923bc782 (patch)
tree59867adf2fffea55fa8d6ff8e8d46d20476fb668 /src/ext/ed25519/ref10/fe_frombytes.c
parent6b155dc1a6c7c7bd345514a31288c260e4588216 (diff)
downloadtor-6129ff320e6510a453922dba01163824923bc782.tar.gz
tor-6129ff320e6510a453922dba01163824923bc782.zip
Use SHL{8,32,64} in ed25519/ref10 to avoid left-shifting negative values
This helps us avoid undefined behavior. It's based on a patch from teor, except that I wrote a perl script to regenerate the patch: #!/usr/bin/perl -p -w -i BEGIN { %vartypes = (); } if (/^[{}]/) { %vartypes = (); } if (/^ *crypto_int(\d+) +([a-zA-Z_][_a-zA-Z0-9]*)/) { $vartypes{$2} = $1; } elsif (/^ *(?:signed +)char +([a-zA-Z_][_a-zA-Z0-9]*)/) { $vartypes{$1} = '8'; } # This fixes at most one shift per line. But that's all the code does. if (/([a-zA-Z_][a-zA-Z_0-9]*) *<< *(\d+)/) { $v = $1; if (exists $vartypes{$v}) { s/$v *<< *(\d+)/SHL$vartypes{$v}($v,$1)/; } } # remove extra parenthesis s/\(SHL64\((.*)\)\)/SHL64\($1\)/; s/\(SHL32\((.*)\)\)/SHL32\($1\)/; s/\(SHL8\((.*)\)\)/SHL8\($1\)/;
Diffstat (limited to 'src/ext/ed25519/ref10/fe_frombytes.c')
-rw-r--r--src/ext/ed25519/ref10/fe_frombytes.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/ext/ed25519/ref10/fe_frombytes.c b/src/ext/ed25519/ref10/fe_frombytes.c
index 87e249427a..98b8e5f7c1 100644
--- a/src/ext/ed25519/ref10/fe_frombytes.c
+++ b/src/ext/ed25519/ref10/fe_frombytes.c
@@ -48,17 +48,17 @@ void fe_frombytes(fe h,const unsigned char *s)
crypto_int64 carry8;
crypto_int64 carry9;
- carry9 = (h9 + (crypto_int64) (1<<24)) >> 25; h0 += carry9 * 19; h9 -= carry9 << 25;
- carry1 = (h1 + (crypto_int64) (1<<24)) >> 25; h2 += carry1; h1 -= carry1 << 25;
- carry3 = (h3 + (crypto_int64) (1<<24)) >> 25; h4 += carry3; h3 -= carry3 << 25;
- carry5 = (h5 + (crypto_int64) (1<<24)) >> 25; h6 += carry5; h5 -= carry5 << 25;
- carry7 = (h7 + (crypto_int64) (1<<24)) >> 25; h8 += carry7; h7 -= carry7 << 25;
+ carry9 = (h9 + (crypto_int64) (1<<24)) >> 25; h0 += carry9 * 19; h9 -= SHL64(carry9,25);
+ carry1 = (h1 + (crypto_int64) (1<<24)) >> 25; h2 += carry1; h1 -= SHL64(carry1,25);
+ carry3 = (h3 + (crypto_int64) (1<<24)) >> 25; h4 += carry3; h3 -= SHL64(carry3,25);
+ carry5 = (h5 + (crypto_int64) (1<<24)) >> 25; h6 += carry5; h5 -= SHL64(carry5,25);
+ carry7 = (h7 + (crypto_int64) (1<<24)) >> 25; h8 += carry7; h7 -= SHL64(carry7,25);
- carry0 = (h0 + (crypto_int64) (1<<25)) >> 26; h1 += carry0; h0 -= carry0 << 26;
- carry2 = (h2 + (crypto_int64) (1<<25)) >> 26; h3 += carry2; h2 -= carry2 << 26;
- carry4 = (h4 + (crypto_int64) (1<<25)) >> 26; h5 += carry4; h4 -= carry4 << 26;
- carry6 = (h6 + (crypto_int64) (1<<25)) >> 26; h7 += carry6; h6 -= carry6 << 26;
- carry8 = (h8 + (crypto_int64) (1<<25)) >> 26; h9 += carry8; h8 -= carry8 << 26;
+ carry0 = (h0 + (crypto_int64) (1<<25)) >> 26; h1 += carry0; h0 -= SHL64(carry0,26);
+ carry2 = (h2 + (crypto_int64) (1<<25)) >> 26; h3 += carry2; h2 -= SHL64(carry2,26);
+ carry4 = (h4 + (crypto_int64) (1<<25)) >> 26; h5 += carry4; h4 -= SHL64(carry4,26);
+ carry6 = (h6 + (crypto_int64) (1<<25)) >> 26; h7 += carry6; h6 -= SHL64(carry6,26);
+ carry8 = (h8 + (crypto_int64) (1<<25)) >> 26; h9 += carry8; h8 -= SHL64(carry8,26);
h[0] = (crypto_int32) h0;
h[1] = (crypto_int32) h1;