2 * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright 2014-2016 Cryptography Research, Inc.
5 * Licensed under the OpenSSL license (the "License"). You may not use
6 * this file except in compliance with the License. You can obtain a copy
7 * in the file LICENSE in the source distribution or at
8 * https://www.openssl.org/source/license.html
10 * Originally written by Mike Hamburg
14 #define LIMB(x) (x##ull)&((1ull<<28)-1), (x##ull)>>28
15 #define FIELD_LITERAL(a,b,c,d,e,f,g,h) \
16 {{LIMB(a),LIMB(b),LIMB(c),LIMB(d),LIMB(e),LIMB(f),LIMB(g),LIMB(h)}}
18 #define LIMB_PLACE_VALUE(i) 28
20 void gf_add_RAW (gf out, const gf a, const gf b) {
21 for (unsigned int i=0; i<sizeof(*out)/sizeof(uint32xn_t); i++) {
22 ((uint32xn_t*)out)[i] = ((const uint32xn_t*)a)[i] + ((const uint32xn_t*)b)[i];
25 for (unsigned int i=0; i<sizeof(*out)/sizeof(out->limb[0]); i++) {
26 out->limb[i] = a->limb[i] + b->limb[i];
31 void gf_sub_RAW (gf out, const gf a, const gf b) {
32 for (unsigned int i=0; i<sizeof(*out)/sizeof(uint32xn_t); i++) {
33 ((uint32xn_t*)out)[i] = ((const uint32xn_t*)a)[i] - ((const uint32xn_t*)b)[i];
36 for (unsigned int i=0; i<sizeof(*out)/sizeof(out->limb[0]); i++) {
37 out->limb[i] = a->limb[i] - b->limb[i];
42 void gf_bias (gf a, int amt) {
43 uint32_t co1 = ((1ull<<28)-1)*amt, co2 = co1-amt;
44 uint32x4_t lo = {co1,co1,co1,co1}, hi = {co2,co1,co1,co1};
45 uint32x4_t *aa = (uint32x4_t*) a;
52 void gf_weak_reduce (gf a) {
53 uint64_t mask = (1ull<<28) - 1;
54 uint64_t tmp = a->limb[15] >> 28;
56 for (unsigned int i=15; i>0; i--) {
57 a->limb[i] = (a->limb[i] & mask) + (a->limb[i-1]>>28);
59 a->limb[0] = (a->limb[0] & mask) + tmp;