Security Scol plugin
donna_sse.h
1// donna_sse.h - written and placed in public domain by Jeffrey Walton
2// Crypto++ specific implementation wrapped around Andrew
3// Moon's public domain curve25519-donna and ed25519-donna,
4// https://github.com/floodyberry/curve25519-donna and
5// https://github.com/floodyberry/ed25519-donna.
6
7// This source file multiplexes two different repos using namespaces. This
8// was a little easier from a project management standpoint. We only need
9// two files per architecture at the expense of namespaces and bloat.
10
11#ifndef CRYPTOPP_DONNA_SSE_H
12#define CRYPTOPP_DONNA_SSE_H
13#ifndef CRYPTOPP_DOXYGEN_PROCESSING
14
15#include "config.h"
16#include <emmintrin.h>
17
18NAMESPACE_BEGIN(CryptoPP)
19NAMESPACE_BEGIN(Donna)
20NAMESPACE_BEGIN(ArchSSE)
21
22using CryptoPP::byte;
23using CryptoPP::word32;
24
25typedef __m128i xmmi;
26#define ALIGN(n) CRYPTOPP_ALIGN_DATA(n)
27
28typedef union packedelem8_t {
29 byte u[16];
30 xmmi v;
32
33typedef union packedelem32_t {
34 word32 u[4];
35 xmmi v;
37
38typedef union packedelem64_t {
39 word64 u[2];
40 xmmi v;
42
43/* 10 elements + an extra 2 to fit in 3 xmm registers */
44typedef word32 bignum25519[12];
45typedef packedelem32 packed32bignum25519[5];
46typedef packedelem64 packed64bignum25519[10];
47
48const word32 reduce_mask_26 = (1 << 26) - 1;
49const word32 reduce_mask_25 = (1 << 25) - 1;
50
51const packedelem32 sse2_bot32bitmask = {{0xffffffff, 0x00000000, 0xffffffff, 0x00000000}};
52const packedelem32 sse2_top32bitmask = {{0x00000000, 0xffffffff, 0x00000000, 0xffffffff}};
53const packedelem32 sse2_top64bitmask = {{0x00000000, 0x00000000, 0xffffffff, 0xffffffff}};
54const packedelem32 sse2_bot64bitmask = {{0xffffffff, 0xffffffff, 0x00000000, 0x00000000}};
55
56/* reduction masks */
57const packedelem64 packedmask26 = {{0x03ffffff, 0x03ffffff}};
58const packedelem64 packedmask25 = {{0x01ffffff, 0x01ffffff}};
59const packedelem32 packedmask2625 = {{0x3ffffff,0,0x1ffffff,0}};
60const packedelem32 packedmask26262626 = {{0x03ffffff, 0x03ffffff, 0x03ffffff, 0x03ffffff}};
61const packedelem32 packedmask25252525 = {{0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff}};
62
63/* multipliers */
64const packedelem64 packednineteen = {{19, 19}};
65const packedelem64 packednineteenone = {{19, 1}};
66const packedelem64 packedthirtyeight = {{38, 38}};
67const packedelem64 packed3819 = {{19*2,19}};
68const packedelem64 packed9638 = {{19*4,19*2}};
69
70/* 121666,121665 */
71const packedelem64 packed121666121665 = {{121666, 121665}};
72
73/* 2*(2^255 - 19) = 0 mod p */
74const packedelem32 packed2p0 = {{0x7ffffda,0x3fffffe,0x7fffffe,0x3fffffe}};
75const packedelem32 packed2p1 = {{0x7fffffe,0x3fffffe,0x7fffffe,0x3fffffe}};
76const packedelem32 packed2p2 = {{0x7fffffe,0x3fffffe,0x0000000,0x0000000}};
77
78const packedelem32 packed32zeromodp0 = {{0x7ffffda,0x7ffffda,0x3fffffe,0x3fffffe}};
79const packedelem32 packed32zeromodp1 = {{0x7fffffe,0x7fffffe,0x3fffffe,0x3fffffe}};
80
81NAMESPACE_END // ArchSSE
82NAMESPACE_END // Donna
83NAMESPACE_END // CryptoPP
84
85#endif // CRYPTOPP_DOXYGEN_PROCESSING
86#endif // CRYPTOPP_DONNA_SSE_H
Library configuration file.
unsigned int word32
32-bit unsigned datatype
Definition config_int.h:62