some tweaks
[mkp224o.git] / ed25519 / amd64-51-30k / sc25519_slide.c
blob4e52010d56fc0c2eabf4712183105dbde7545de5
1 #include "sc25519.h"
3 void sc25519_slide(signed char r[256], const sc25519 *s, int swindowsize)
5 int i,j,k,b,m=(1<<(swindowsize-1))-1, soplen=256;
6 unsigned long long sv0 = s->v[0];
7 unsigned long long sv1 = s->v[1];
8 unsigned long long sv2 = s->v[2];
9 unsigned long long sv3 = s->v[3];
11 /* first put the binary expansion into r */
12 for(i=0;i<64;i++) {
13 r[i] = sv0 & 1;
14 r[i+64] = sv1 & 1;
15 r[i+128] = sv2 & 1;
16 r[i+192] = sv3 & 1;
17 sv0 >>= 1;
18 sv1 >>= 1;
19 sv2 >>= 1;
20 sv3 >>= 1;
23 /* Making it sliding window */
24 for (j = 0;j < soplen;++j)
26 if (r[j]) {
27 for (b = 1;b < soplen - j && b <= 6;++b) {
28 if (r[j] + (r[j + b] << b) <= m)
30 r[j] += r[j + b] << b; r[j + b] = 0;
32 else if (r[j] - (r[j + b] << b) >= -m)
34 r[j] -= r[j + b] << b;
35 for (k = j + b;k < soplen;++k)
37 if (!r[k]) {
38 r[k] = 1;
39 break;
41 r[k] = 0;
44 else if (r[j + b])
45 break;