f_impl.h 938 Bytes
Newer Older
1
/* Copyright (c) 2014-2016 Cryptography Research, Inc.
2 3 4
 * Released under the MIT License.  See LICENSE.txt for license information.
 */

5 6
#define LIMB_PLACE_VALUE(i) 58

7
void gf_add_RAW (gf out, const gf a, const gf b) {
8
    for (unsigned int i=0; i<9; i++) {
9 10
        out->limb[i] = a->limb[i] + b->limb[i];
    }
11
    gf_weak_reduce(out);
12 13
}

14
void gf_sub_RAW (gf out, const gf a, const gf b) {
15
    uint64_t co1 = ((1ull<<58)-1)*4, co2 = ((1ull<<57)-1)*4;
16
    for (unsigned int i=0; i<9; i++) {
17 18
        out->limb[i] = a->limb[i] - b->limb[i] + ((i==8) ? co2 : co1);
    }
19
    gf_weak_reduce(out);
20 21
}

22
void gf_bias (gf a, int amt) {
23 24 25 26
    (void) a;
    (void) amt;
}

27
void gf_weak_reduce (gf a) {
28 29
    uint64_t mask = (1ull<<58) - 1;
    uint64_t tmp = a->limb[8] >> 57;
30
    for (unsigned int i=8; i>0; i--) {
31 32 33 34
        a->limb[i] = (a->limb[i] & ((i==8) ? mask>>1 : mask)) + (a->limb[i-1]>>58);
    }
    a->limb[0] = (a->limb[0] & mask) + tmp;
}