File: sc_cmov.c

package info (click to toggle)
python-axolotl-curve25519 0.4.1.post2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 664 kB
  • sloc: ansic: 5,207; python: 34; makefile: 4
file content (21 lines) | stat: -rw-r--r-- 465 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "crypto_additions.h"

/*
Replace (f,g) with (g,g) if b == 1;
replace (f,g) with (f,g) if b == 0.

Preconditions: b in {0,1}.
*/

void sc_cmov(unsigned char* f, const unsigned char* g, unsigned char b)
{
  int count=32;
  unsigned char x[32];
  for (count=0; count < 32; count++)
    x[count] = f[count] ^ g[count];
  b = -b;
  for (count=0; count < 32; count++)
    x[count] &= b;
  for (count=0; count < 32; count++)
    f[count] = f[count] ^ x[count];
}