File: f_impl.h

package info (click to toggle)
haskell-crypton 0.34-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,380 kB
  • sloc: ansic: 22,092; haskell: 18,717; makefile: 6
file content (38 lines) | stat: -rw-r--r-- 1,101 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* Copyright (c) 2014-2016 Cryptography Research, Inc.
 * Released under the MIT License.  See LICENSE.txt for license information.
 */

#define GF_HEADROOM 9999 /* Everything is reduced anyway */
#define FIELD_LITERAL(a,b,c,d,e,f,g,h) {{a,b,c,d,e,f,g,h}}
    
#define LIMB_PLACE_VALUE(i) 56

void crypton_gf_add_RAW (gf out, const gf a, const gf b) {
    for (unsigned int i=0; i<8; i++) {
        out->limb[i] = a->limb[i] + b->limb[i];
    }
    crypton_gf_weak_reduce(out);
}

void crypton_gf_sub_RAW (gf out, const gf a, const gf b) {
    uint64_t co1 = ((1ull<<56)-1)*2, co2 = co1-2;
    for (unsigned int i=0; i<8; i++) {
        out->limb[i] = a->limb[i] - b->limb[i] + ((i==4) ? co2 : co1);
    }
    crypton_gf_weak_reduce(out);
}

void crypton_gf_bias (gf a, int amt) {
    (void) a;
    (void) amt;
}

void crypton_gf_weak_reduce (gf a) {
    uint64_t mask = (1ull<<56) - 1;
    uint64_t tmp = a->limb[7] >> 56;
    a->limb[4] += tmp;
    for (unsigned int i=7; i>0; i--) {
        a->limb[i] = (a->limb[i] & mask) + (a->limb[i-1]>>56);
    }
    a->limb[0] = (a->limb[0] & mask) + tmp;
}