aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/restricted/aws/s2n/pq-crypto/bike_r1/gf2x.h
blob: 7fb169505898241cea22f77eae54b2d29e0ce6bf (plain) (blame)
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
47
48
49
50
51
52
53
54
55
/* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 
 * SPDX-License-Identifier: Apache-2.0" 
 * 
 * Written by Nir Drucker and Shay Gueron, 
 * AWS Cryptographic Algorithms Group. 
 * (ndrucker@amazon.com, gueron@amazon.com) 
 */ 
 
#pragma once 
 
#include "types.h" 
 
#ifdef USE_OPENSSL 
#  include "openssl_utils.h" 
#endif 
 
#ifdef USE_OPENSSL_GF2M 
// res = a*b mod (x^r - 1) 
// Note: the caller must allocate twice the size of res. 
_INLINE_ ret_t 
gf2x_mod_mul(OUT uint64_t *res, IN const uint64_t *a, IN const uint64_t *b) 
{ 
  return cyclic_product((uint8_t *)res, (const uint8_t *)a, (const uint8_t *)b); 
} 
 
// A wrapper for other gf2x_add implementations. 
_INLINE_ ret_t 
gf2x_add(OUT uint8_t *res, 
         IN const uint8_t *a, 
         IN const uint8_t *b, 
         IN const uint64_t size) 
{ 
  BIKE_UNUSED(size); 
  return ossl_add((uint8_t *)res, a, b); 
} 
#else // USE_OPENSSL_GF2M 
 
_INLINE_ ret_t 
gf2x_add(OUT uint8_t *res, 
         IN const uint8_t *a, 
         IN const uint8_t *b, 
         IN const uint64_t bytelen) 
{ 
  for(uint64_t i = 0; i < bytelen; i++) 
  { 
    res[i] = a[i] ^ b[i]; 
  } 
  return SUCCESS; 
} 
 
// res = a*b mod (x^r - 1) 
// the caller must allocate twice the size of res! 
ret_t 
gf2x_mod_mul(OUT uint64_t *res, IN const uint64_t *a, IN const uint64_t *b); 
#endif