2017-12-01 18:12:25 +00:00
|
|
|
/*
|
2018-01-18 13:12:46 +00:00
|
|
|
* Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
|
2017-12-01 18:12:25 +00:00
|
|
|
* Copyright 2014-2016 Cryptography Research, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
|
|
|
*
|
|
|
|
* Originally written by Mike Hamburg
|
2017-11-15 15:27:21 +00:00
|
|
|
*/
|
2018-02-12 14:27:02 +00:00
|
|
|
|
|
|
|
#ifndef HEADER_ARCH_32_F_IMPL_H
|
|
|
|
# define HEADER_ARCH_32_F_IMPL_H
|
|
|
|
|
|
|
|
# define GF_HEADROOM 2
|
|
|
|
# define LIMB(x) (x)&((1<<28)-1), (x)>>28
|
|
|
|
# define FIELD_LITERAL(a,b,c,d,e,f,g,h) \
|
2017-11-15 15:27:21 +00:00
|
|
|
{{LIMB(a),LIMB(b),LIMB(c),LIMB(d),LIMB(e),LIMB(f),LIMB(g),LIMB(h)}}
|
2017-12-04 11:38:58 +00:00
|
|
|
|
2018-02-12 14:27:02 +00:00
|
|
|
# define LIMB_PLACE_VALUE(i) 28
|
2017-11-15 15:27:21 +00:00
|
|
|
|
2017-12-04 11:38:58 +00:00
|
|
|
void gf_add_RAW(gf out, const gf a, const gf b)
|
|
|
|
{
|
2018-01-18 12:55:23 +00:00
|
|
|
unsigned int i;
|
|
|
|
|
2018-01-31 13:53:45 +00:00
|
|
|
for (i = 0; i < NLIMBS; i++) {
|
2017-11-15 15:27:21 +00:00
|
|
|
out->limb[i] = a->limb[i] + b->limb[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-04 11:38:58 +00:00
|
|
|
void gf_sub_RAW(gf out, const gf a, const gf b)
|
|
|
|
{
|
2018-01-18 12:55:23 +00:00
|
|
|
unsigned int i;
|
|
|
|
|
2018-02-01 14:23:13 +00:00
|
|
|
for (i = 0; i < NLIMBS; i++) {
|
2017-11-15 15:27:21 +00:00
|
|
|
out->limb[i] = a->limb[i] - b->limb[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-04 11:38:58 +00:00
|
|
|
void gf_bias(gf a, int amt)
|
|
|
|
{
|
2018-01-18 12:55:23 +00:00
|
|
|
unsigned int i;
|
2017-12-04 11:38:58 +00:00
|
|
|
uint32_t co1 = ((1 << 28) - 1) * amt, co2 = co1 - amt;
|
2018-01-18 12:55:23 +00:00
|
|
|
|
2018-02-01 14:23:13 +00:00
|
|
|
for (i = 0; i < NLIMBS; i++)
|
2017-12-04 11:38:58 +00:00
|
|
|
a->limb[i] += (i == sizeof(*a) / sizeof(a->limb[0]) / 2) ? co2 : co1;
|
2017-11-15 15:27:21 +00:00
|
|
|
}
|
|
|
|
|
2017-12-04 11:38:58 +00:00
|
|
|
void gf_weak_reduce(gf a)
|
|
|
|
{
|
|
|
|
uint32_t mask = (1 << 28) - 1;
|
2017-11-15 15:27:21 +00:00
|
|
|
uint32_t tmp = a->limb[15] >> 28;
|
2018-01-18 12:55:23 +00:00
|
|
|
unsigned int i;
|
|
|
|
|
2017-11-15 15:27:21 +00:00
|
|
|
a->limb[8] += tmp;
|
2017-12-04 13:30:53 +00:00
|
|
|
for (i = 15; i > 0; i--)
|
2017-12-04 11:38:58 +00:00
|
|
|
a->limb[i] = (a->limb[i] & mask) + (a->limb[i - 1] >> 28);
|
2017-11-15 15:27:21 +00:00
|
|
|
a->limb[0] = (a->limb[0] & mask) + tmp;
|
|
|
|
}
|
2018-02-12 14:27:02 +00:00
|
|
|
|
|
|
|
#endif /* HEADER_ARCH_32_F_IMPL_H */
|