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)
22 for (unsigned int i = 0; i < sizeof(*out) / sizeof(uint32xn_t); i++) {
23 ((uint32xn_t *) out)[i] =
24 ((const uint32xn_t *)a)[i] + ((const uint32xn_t *)b)[i];
28 void gf_sub_RAW(gf out, const gf a, const gf b)
30 for (unsigned int i = 0; i < sizeof(*out) / sizeof(uint32xn_t); i++) {
31 ((uint32xn_t *) out)[i] =
32 ((const uint32xn_t *)a)[i] - ((const uint32xn_t *)b)[i];
36 void gf_bias(gf a, int amt)
38 uint32_t co1 = ((1ull << 28) - 1) * amt, co2 = co1 - amt;
39 uint32x4_t lo = { co1, co1, co1, co1 }, hi = {
41 uint32x4_t *aa = (uint32x4_t *) a;
49 void gf_weak_reduce(gf a)
51 uint64_t mask = (1ull << 28) - 1;
52 uint64_t tmp = a->limb[15] >> 28;
55 for (unsigned int i = 15; i > 0; i--) {
56 a->limb[i] = (a->limb[i] & mask) + (a->limb[i - 1] >> 28);
58 a->limb[0] = (a->limb[0] & mask) + tmp;