File: f_arithmetic.c

package info (click to toggle)
haskell-cryptonite 0.29-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,368 kB
  • sloc: ansic: 22,009; haskell: 18,416; makefile: 8
file content (46 lines) | stat: -rw-r--r-- 1,491 bytes parent folder | download | duplicates (4)
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
39
40
41
42
43
44
45
46
/**
 * @cond internal
 * @file f_arithmetic.c
 * @copyright
 *   Copyright (c) 2014 Cryptography Research, Inc.  \n
 *   Released under the MIT License.  See LICENSE.txt for license information.
 * @author Mike Hamburg
 * @brief Field-specific arithmetic.
 */

#include "field.h"

mask_t cryptonite_gf_isr (
    gf a,
    const gf x
) {
    gf L0, L1, L2;
    cryptonite_gf_sqr  (L1,     x );
    cryptonite_gf_mul  (L2,     x,   L1 );
    cryptonite_gf_sqr  (L1,   L2 );
    cryptonite_gf_mul  (L2,     x,   L1 );
    cryptonite_gf_sqrn (L1,   L2,     3 );
    cryptonite_gf_mul  (L0,   L2,   L1 );
    cryptonite_gf_sqrn (L1,   L0,     3 );
    cryptonite_gf_mul  (L0,   L2,   L1 );
    cryptonite_gf_sqrn (L2,   L0,     9 );
    cryptonite_gf_mul  (L1,   L0,   L2 );
    cryptonite_gf_sqr  (L0,   L1 );
    cryptonite_gf_mul  (L2,     x,   L0 );
    cryptonite_gf_sqrn (L0,   L2,    18 );
    cryptonite_gf_mul  (L2,   L1,   L0 );
    cryptonite_gf_sqrn (L0,   L2,    37 );
    cryptonite_gf_mul  (L1,   L2,   L0 );
    cryptonite_gf_sqrn (L0,   L1,    37 );
    cryptonite_gf_mul  (L1,   L2,   L0 );
    cryptonite_gf_sqrn (L0,   L1,   111 );
    cryptonite_gf_mul  (L2,   L1,   L0 );
    cryptonite_gf_sqr  (L0,   L2 );
    cryptonite_gf_mul  (L1,     x,   L0 );
    cryptonite_gf_sqrn (L0,   L1,   223 );
    cryptonite_gf_mul  (L1,   L2,   L0 );
    cryptonite_gf_sqr  (L2, L1);
    cryptonite_gf_mul  (L0, L2, x);
    cryptonite_gf_copy(a,L1);
    return cryptonite_gf_eq(L0,ONE);
}