• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
3  *
4  *  Licensed under the Apache License, Version 2.0 (the License); you may
5  *  not use this file except in compliance with the License.
6  *
7  *  http://www.apache.org/licenses/LICENSE-2.0
8  */
9 
10 
11 /* GF(2^128) defined by f(x) = x^128 + x^7 + x^2 + x + 1
12  * A + B mod f(x) = a xor b
13  * A * 2 mod f(x)
14  */
15 
16 #ifndef GMSSL_GF128_H
17 #define GMSSL_GF128_H
18 
19 
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <stdint.h>
24 
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 //typedef unsigned __int128 gf128_t;
31 
32 typedef struct {
33 	uint64_t hi;
34 	uint64_t lo;
35 } gf128_t;
36 
37 
38 // Note: send by value is comptabile with uint128_t and sse2
39 gf128_t gf128_from_hex(const char *s);
40 int gf128_equ_hex(gf128_t a, const char *s);
41 gf128_t gf128_zero(void);
42 gf128_t gf128_add(gf128_t a, gf128_t b);
43 gf128_t gf128_mul(gf128_t a, gf128_t b);
44 gf128_t gf128_mul2(gf128_t a);
45 gf128_t gf128_from_bytes(const uint8_t p[16]);
46 void gf128_to_bytes(gf128_t a, uint8_t p[16]);
47 int gf128_print(FILE *fp, int fmt ,int ind, const char *label, gf128_t a);
48 
49 
50 #ifdef __cplusplus
51 }
52 #endif
53 #endif
54