Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:55:01

0001 // donna_sse.h - written and placed in public domain by Jeffrey Walton

0002 //               Crypto++ specific implementation wrapped around Andrew

0003 //               Moon's public domain curve25519-donna and ed25519-donna,

0004 //               https://github.com/floodyberry/curve25519-donna and

0005 //               https://github.com/floodyberry/ed25519-donna.

0006 
0007 // This source file multiplexes two different repos using namespaces. This

0008 // was a little easier from a project management standpoint. We only need

0009 // two files per architecture at the expense of namespaces and bloat.

0010 
0011 #ifndef CRYPTOPP_DONNA_SSE_H
0012 #define CRYPTOPP_DONNA_SSE_H
0013 #ifndef CRYPTOPP_DOXYGEN_PROCESSING
0014 
0015 #include "config.h"
0016 #include <emmintrin.h>
0017 
0018 NAMESPACE_BEGIN(CryptoPP)
0019 NAMESPACE_BEGIN(Donna)
0020 NAMESPACE_BEGIN(ArchSSE)
0021 
0022 using CryptoPP::byte;
0023 using CryptoPP::word32;
0024 
0025 typedef __m128i xmmi;
0026 #define ALIGN(n) CRYPTOPP_ALIGN_DATA(n)
0027 
0028 typedef union packedelem8_t {
0029     byte u[16];
0030     xmmi v;
0031 } packedelem8;
0032 
0033 typedef union packedelem32_t {
0034     word32 u[4];
0035     xmmi v;
0036 } packedelem32;
0037 
0038 typedef union packedelem64_t {
0039     word64 u[2];
0040     xmmi v;
0041 } packedelem64;
0042 
0043 /* 10 elements + an extra 2 to fit in 3 xmm registers */
0044 typedef word32 bignum25519[12];
0045 typedef packedelem32 packed32bignum25519[5];
0046 typedef packedelem64 packed64bignum25519[10];
0047 
0048 const word32 reduce_mask_26 = (1 << 26) - 1;
0049 const word32 reduce_mask_25 = (1 << 25) - 1;
0050 
0051 const packedelem32 sse2_bot32bitmask = {{0xffffffff, 0x00000000, 0xffffffff, 0x00000000}};
0052 const packedelem32 sse2_top32bitmask = {{0x00000000, 0xffffffff, 0x00000000, 0xffffffff}};
0053 const packedelem32 sse2_top64bitmask = {{0x00000000, 0x00000000, 0xffffffff, 0xffffffff}};
0054 const packedelem32 sse2_bot64bitmask = {{0xffffffff, 0xffffffff, 0x00000000, 0x00000000}};
0055 
0056 /* reduction masks */
0057 const packedelem64 packedmask26 = {{0x03ffffff, 0x03ffffff}};
0058 const packedelem64 packedmask25 = {{0x01ffffff, 0x01ffffff}};
0059 const packedelem32 packedmask2625 = {{0x3ffffff,0,0x1ffffff,0}};
0060 const packedelem32 packedmask26262626 = {{0x03ffffff, 0x03ffffff, 0x03ffffff, 0x03ffffff}};
0061 const packedelem32 packedmask25252525 = {{0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff}};
0062 
0063 /* multipliers */
0064 const packedelem64 packednineteen = {{19, 19}};
0065 const packedelem64 packednineteenone = {{19, 1}};
0066 const packedelem64 packedthirtyeight = {{38, 38}};
0067 const packedelem64 packed3819 = {{19*2,19}};
0068 const packedelem64 packed9638 = {{19*4,19*2}};
0069 
0070 /* 121666,121665 */
0071 const packedelem64 packed121666121665 = {{121666, 121665}};
0072 
0073 /* 2*(2^255 - 19) = 0 mod p */
0074 const packedelem32 packed2p0 = {{0x7ffffda,0x3fffffe,0x7fffffe,0x3fffffe}};
0075 const packedelem32 packed2p1 = {{0x7fffffe,0x3fffffe,0x7fffffe,0x3fffffe}};
0076 const packedelem32 packed2p2 = {{0x7fffffe,0x3fffffe,0x0000000,0x0000000}};
0077 
0078 const packedelem32 packed32zeromodp0 = {{0x7ffffda,0x7ffffda,0x3fffffe,0x3fffffe}};
0079 const packedelem32 packed32zeromodp1 = {{0x7fffffe,0x7fffffe,0x3fffffe,0x3fffffe}};
0080 
0081 NAMESPACE_END  // ArchSSE

0082 NAMESPACE_END  // Donna

0083 NAMESPACE_END  // CryptoPP

0084 
0085 #endif  // CRYPTOPP_DOXYGEN_PROCESSING

0086 #endif  // CRYPTOPP_DONNA_SSE_H