Debian Codegraph @

curve/ed25519/additions/sc_cmov.c

raw
1 #include "crypto_additions.h"
2
3 /*
4 Replace (f,g) with (g,g) if b == 1;
5 replace (f,g) with (f,g) if b == 0.
6
7 Preconditions: b in {0,1}.
8 */
9
10 void sc_cmov(unsigned char* f, const unsigned char* g, unsigned char b)
11 {
12 int count=32;
13 unsigned char x[32];
14 for (count=0; count < 32; count++)
15 x[count] = f[count] ^ g[count];
16 b = -b;
17 for (count=0; count < 32; count++)
18 x[count] &= b;
19 for (count=0; count < 32; count++)
20 f[count] = f[count] ^ x[count];
21 }