@@ -1815,14 +1815,14 @@ do { \
18151815 */
18161816#define SHAKE256_SET_HASH_X4_16 (state , hash ) \
18171817do { \
1818- (state)[24] = ((word64*)(( hash) + 0 * 16))[0]; \
1819- (state)[25] = ((word64*)(( hash) + 1 * 16))[0]; \
1820- (state)[26] = ((word64*)(( hash) + 2 * 16))[0]; \
1821- (state)[27] = ((word64*)(( hash) + 3 * 16))[0]; \
1822- (state)[28] = ((word64*)(( hash) + 0 * 16))[1]; \
1823- (state)[29] = ((word64*)(( hash) + 1 * 16))[1]; \
1824- (state)[30] = ((word64*)(( hash) + 2 * 16))[1]; \
1825- (state)[31] = ((word64*)(( hash) + 3 * 16))[1]; \
1818+ (state)[24] = readUnalignedWord64(( hash) + 0 * 16 + 0 * 8); \
1819+ (state)[25] = readUnalignedWord64(( hash) + 1 * 16 + 0 * 8); \
1820+ (state)[26] = readUnalignedWord64(( hash) + 2 * 16 + 0 * 8); \
1821+ (state)[27] = readUnalignedWord64(( hash) + 3 * 16 + 0 * 8); \
1822+ (state)[28] = readUnalignedWord64(( hash) + 0 * 16 + 1 * 8); \
1823+ (state)[29] = readUnalignedWord64(( hash) + 1 * 16 + 1 * 8); \
1824+ (state)[30] = readUnalignedWord64(( hash) + 2 * 16 + 1 * 8); \
1825+ (state)[31] = readUnalignedWord64(( hash) + 3 * 16 + 1 * 8); \
18261826} while (0)
18271827
18281828/* Get the four SHAKE-256 16-byte hash results.
@@ -1832,14 +1832,14 @@ do { \
18321832 */
18331833#define SHAKE256_GET_HASH_X4_16 (state , hash ) \
18341834do { \
1835- ((word64*)(( hash) + 0 * 16))[0] = (state)[0]; \
1836- ((word64*)(( hash) + 1 * 16))[0] = (state)[1]; \
1837- ((word64*)(( hash) + 2 * 16))[0] = (state)[2]; \
1838- ((word64*)(( hash) + 3 * 16))[0] = (state)[3]; \
1839- ((word64*)(( hash) + 0 * 16))[1] = (state)[4]; \
1840- ((word64*)(( hash) + 1 * 16))[1] = (state)[5]; \
1841- ((word64*)(( hash) + 2 * 16))[1] = (state)[6]; \
1842- ((word64*)(( hash) + 3 * 16))[1] = (state)[7]; \
1835+ writeUnalignedWord64(( hash) + 0 * 16 + 0 * 8, (state)[0]); \
1836+ writeUnalignedWord64(( hash) + 1 * 16 + 0 * 8, (state)[1]); \
1837+ writeUnalignedWord64(( hash) + 2 * 16 + 0 * 8, (state)[2]); \
1838+ writeUnalignedWord64(( hash) + 3 * 16 + 0 * 8, (state)[3]); \
1839+ writeUnalignedWord64(( hash) + 0 * 16 + 1 * 8, (state)[4]); \
1840+ writeUnalignedWord64(( hash) + 1 * 16 + 1 * 8, (state)[5]); \
1841+ writeUnalignedWord64(( hash) + 2 * 16 + 1 * 8, (state)[6]); \
1842+ writeUnalignedWord64(( hash) + 3 * 16 + 1 * 8, (state)[7]); \
18431843} while (0)
18441844#endif
18451845
@@ -1876,18 +1876,18 @@ do { \
18761876 */
18771877#define SHAKE256_SET_HASH_X4_24 (state , hash ) \
18781878do { \
1879- (state)[28] = ((word64*)(( hash) + 0 * 24))[0]; \
1880- (state)[29] = ((word64*)(( hash) + 1 * 24))[0]; \
1881- (state)[30] = ((word64*)(( hash) + 2 * 24))[0]; \
1882- (state)[31] = ((word64*)(( hash) + 3 * 24))[0]; \
1883- (state)[32] = ((word64*)(( hash) + 0 * 24))[1]; \
1884- (state)[33] = ((word64*)(( hash) + 1 * 24))[1]; \
1885- (state)[34] = ((word64*)(( hash) + 2 * 24))[1]; \
1886- (state)[35] = ((word64*)(( hash) + 3 * 24))[1]; \
1887- (state)[36] = ((word64*)(( hash) + 0 * 24))[2]; \
1888- (state)[37] = ((word64*)(( hash) + 1 * 24))[2]; \
1889- (state)[38] = ((word64*)(( hash) + 2 * 24))[2]; \
1890- (state)[39] = ((word64*)(( hash) + 3 * 24))[2]; \
1879+ (state)[28] = readUnalignedWord64(( hash) + 0 * 24 + 0 * 8); \
1880+ (state)[29] = readUnalignedWord64(( hash) + 1 * 24 + 0 * 8); \
1881+ (state)[30] = readUnalignedWord64(( hash) + 2 * 24 + 0 * 8); \
1882+ (state)[31] = readUnalignedWord64(( hash) + 3 * 24 + 0 * 8); \
1883+ (state)[32] = readUnalignedWord64(( hash) + 0 * 24 + 1 * 8); \
1884+ (state)[33] = readUnalignedWord64(( hash) + 1 * 24 + 1 * 8); \
1885+ (state)[34] = readUnalignedWord64(( hash) + 2 * 24 + 1 * 8); \
1886+ (state)[35] = readUnalignedWord64(( hash) + 3 * 24 + 1 * 8); \
1887+ (state)[36] = readUnalignedWord64(( hash) + 0 * 24 + 2 * 8); \
1888+ (state)[37] = readUnalignedWord64(( hash) + 1 * 24 + 2 * 8); \
1889+ (state)[38] = readUnalignedWord64(( hash) + 2 * 24 + 2 * 8); \
1890+ (state)[39] = readUnalignedWord64(( hash) + 3 * 24 + 2 * 8); \
18911891} while (0)
18921892
18931893/* Get the four SHAKE-256 24-byte (hash) results.
@@ -1897,18 +1897,18 @@ do { \
18971897 */
18981898#define SHAKE256_GET_HASH_X4_24 (state , hash ) \
18991899do { \
1900- ((word64*)(( hash) + 0 * 24))[0] = (state)[ 0]; \
1901- ((word64*)(( hash) + 1 * 24))[0] = (state)[ 1]; \
1902- ((word64*)(( hash) + 2 * 24))[0] = (state)[ 2]; \
1903- ((word64*)(( hash) + 3 * 24))[0] = (state)[ 3]; \
1904- ((word64*)(( hash) + 0 * 24))[1] = (state)[ 4]; \
1905- ((word64*)(( hash) + 1 * 24))[1] = (state)[ 5]; \
1906- ((word64*)(( hash) + 2 * 24))[1] = (state)[ 6]; \
1907- ((word64*)(( hash) + 3 * 24))[1] = (state)[ 7]; \
1908- ((word64*)(( hash) + 0 * 24))[2] = (state)[ 8]; \
1909- ((word64*)(( hash) + 1 * 24))[2] = (state)[ 9]; \
1910- ((word64*)(( hash) + 2 * 24))[2] = (state)[10]; \
1911- ((word64*)(( hash) + 3 * 24))[2] = (state)[11]; \
1900+ writeUnalignedWord64(( hash) + 0 * 24 + 0 * 8, (state)[ 0]); \
1901+ writeUnalignedWord64(( hash) + 1 * 24 + 0 * 8, (state)[ 1]); \
1902+ writeUnalignedWord64(( hash) + 2 * 24 + 0 * 8, (state)[ 2]); \
1903+ writeUnalignedWord64(( hash) + 3 * 24 + 0 * 8, (state)[ 3]); \
1904+ writeUnalignedWord64(( hash) + 0 * 24 + 1 * 8, (state)[ 4]); \
1905+ writeUnalignedWord64(( hash) + 1 * 24 + 1 * 8, (state)[ 5]); \
1906+ writeUnalignedWord64(( hash) + 2 * 24 + 1 * 8, (state)[ 6]); \
1907+ writeUnalignedWord64(( hash) + 3 * 24 + 1 * 8, (state)[ 7]); \
1908+ writeUnalignedWord64(( hash) + 0 * 24 + 2 * 8, (state)[ 8]); \
1909+ writeUnalignedWord64(( hash) + 1 * 24 + 2 * 8, (state)[ 9]); \
1910+ writeUnalignedWord64(( hash) + 2 * 24 + 2 * 8, (state)[10]); \
1911+ writeUnalignedWord64(( hash) + 3 * 24 + 2 * 8, (state)[11]); \
19121912} while (0)
19131913#endif
19141914
@@ -1947,22 +1947,22 @@ do { \
19471947 */
19481948#define SHAKE256_SET_HASH_X4_32 (state , hash ) \
19491949do { \
1950- (state)[32] = ((word64*)(( hash) + 0 * 32))[0]; \
1951- (state)[33] = ((word64*)(( hash) + 1 * 32))[0]; \
1952- (state)[34] = ((word64*)(( hash) + 2 * 32))[0]; \
1953- (state)[35] = ((word64*)(( hash) + 3 * 32))[0]; \
1954- (state)[36] = ((word64*)(( hash) + 0 * 32))[1]; \
1955- (state)[37] = ((word64*)(( hash) + 1 * 32))[1]; \
1956- (state)[38] = ((word64*)(( hash) + 2 * 32))[1]; \
1957- (state)[39] = ((word64*)(( hash) + 3 * 32))[1]; \
1958- (state)[40] = ((word64*)(( hash) + 0 * 32))[2]; \
1959- (state)[41] = ((word64*)(( hash) + 1 * 32))[2]; \
1960- (state)[42] = ((word64*)(( hash) + 2 * 32))[2]; \
1961- (state)[43] = ((word64*)(( hash) + 3 * 32))[2]; \
1962- (state)[44] = ((word64*)(( hash) + 0 * 32))[3]; \
1963- (state)[45] = ((word64*)(( hash) + 1 * 32))[3]; \
1964- (state)[46] = ((word64*)(( hash) + 2 * 32))[3]; \
1965- (state)[47] = ((word64*)(( hash) + 3 * 32))[3]; \
1950+ (state)[32] = readUnalignedWord64(( hash) + 0 * 32 + 0 * 8); \
1951+ (state)[33] = readUnalignedWord64(( hash) + 1 * 32 + 0 * 8); \
1952+ (state)[34] = readUnalignedWord64(( hash) + 2 * 32 + 0 * 8); \
1953+ (state)[35] = readUnalignedWord64(( hash) + 3 * 32 + 0 * 8); \
1954+ (state)[36] = readUnalignedWord64(( hash) + 0 * 32 + 1 * 8); \
1955+ (state)[37] = readUnalignedWord64(( hash) + 1 * 32 + 1 * 8); \
1956+ (state)[38] = readUnalignedWord64(( hash) + 2 * 32 + 1 * 8); \
1957+ (state)[39] = readUnalignedWord64(( hash) + 3 * 32 + 1 * 8); \
1958+ (state)[40] = readUnalignedWord64(( hash) + 0 * 32 + 2 * 8); \
1959+ (state)[41] = readUnalignedWord64(( hash) + 1 * 32 + 2 * 8); \
1960+ (state)[42] = readUnalignedWord64(( hash) + 2 * 32 + 2 * 8); \
1961+ (state)[43] = readUnalignedWord64(( hash) + 3 * 32 + 2 * 8); \
1962+ (state)[44] = readUnalignedWord64(( hash) + 0 * 32 + 3 * 8); \
1963+ (state)[45] = readUnalignedWord64(( hash) + 1 * 32 + 3 * 8); \
1964+ (state)[46] = readUnalignedWord64(( hash) + 2 * 32 + 3 * 8); \
1965+ (state)[47] = readUnalignedWord64(( hash) + 3 * 32 + 3 * 8); \
19661966} while (0)
19671967
19681968/* Get the four SHAKE-256 32-byte hash results.
@@ -1972,22 +1972,22 @@ do { \
19721972 */
19731973#define SHAKE256_GET_HASH_X4_32 (state , hash ) \
19741974do { \
1975- ((word64*)(( hash) + 0 * 32))[0] = (state)[ 0]; \
1976- ((word64*)(( hash) + 1 * 32))[0] = (state)[ 1]; \
1977- ((word64*)(( hash) + 2 * 32))[0] = (state)[ 2]; \
1978- ((word64*)(( hash) + 3 * 32))[0] = (state)[ 3]; \
1979- ((word64*)(( hash) + 0 * 32))[1] = (state)[ 4]; \
1980- ((word64*)(( hash) + 1 * 32))[1] = (state)[ 5]; \
1981- ((word64*)(( hash) + 2 * 32))[1] = (state)[ 6]; \
1982- ((word64*)(( hash) + 3 * 32))[1] = (state)[ 7]; \
1983- ((word64*)(( hash) + 0 * 32))[2] = (state)[ 8]; \
1984- ((word64*)(( hash) + 1 * 32))[2] = (state)[ 9]; \
1985- ((word64*)(( hash) + 2 * 32))[2] = (state)[10]; \
1986- ((word64*)(( hash) + 3 * 32))[2] = (state)[11]; \
1987- ((word64*)(( hash) + 0 * 32))[3] = (state)[12]; \
1988- ((word64*)(( hash) + 1 * 32))[3] = (state)[13]; \
1989- ((word64*)(( hash) + 2 * 32))[3] = (state)[14]; \
1990- ((word64*)(( hash) + 3 * 32))[3] = (state)[15]; \
1975+ writeUnalignedWord64(( hash) + 0 * 32 + 0 * 8, (state)[ 0]); \
1976+ writeUnalignedWord64(( hash) + 1 * 32 + 0 * 8, (state)[ 1]); \
1977+ writeUnalignedWord64(( hash) + 2 * 32 + 0 * 8, (state)[ 2]); \
1978+ writeUnalignedWord64(( hash) + 3 * 32 + 0 * 8, (state)[ 3]); \
1979+ writeUnalignedWord64(( hash) + 0 * 32 + 1 * 8, (state)[ 4]); \
1980+ writeUnalignedWord64(( hash) + 1 * 32 + 1 * 8, (state)[ 5]); \
1981+ writeUnalignedWord64(( hash) + 2 * 32 + 1 * 8, (state)[ 6]); \
1982+ writeUnalignedWord64(( hash) + 3 * 32 + 1 * 8, (state)[ 7]); \
1983+ writeUnalignedWord64(( hash) + 0 * 32 + 2 * 8, (state)[ 8]); \
1984+ writeUnalignedWord64(( hash) + 1 * 32 + 2 * 8, (state)[ 9]); \
1985+ writeUnalignedWord64(( hash) + 2 * 32 + 2 * 8, (state)[10]); \
1986+ writeUnalignedWord64(( hash) + 3 * 32 + 2 * 8, (state)[11]); \
1987+ writeUnalignedWord64(( hash) + 0 * 32 + 3 * 8, (state)[12]); \
1988+ writeUnalignedWord64(( hash) + 1 * 32 + 3 * 8, (state)[13]); \
1989+ writeUnalignedWord64(( hash) + 2 * 32 + 3 * 8, (state)[14]); \
1990+ writeUnalignedWord64(( hash) + 3 * 32 + 3 * 8, (state)[15]); \
19911991} while (0)
19921992#endif
19931993
@@ -2084,10 +2084,10 @@ static void slhdsakey_shake256_get_hash_x4(const word64* state, byte* hash,
20842084 int i ;
20852085
20862086 for (i = 0 ; i < (n / 8 ); i ++ ) {
2087- (( word64 * )( hash + 0 * n ))[ i ] = state [4 * i + 0 ];
2088- (( word64 * )( hash + 1 * n ))[ i ] = state [4 * i + 1 ];
2089- (( word64 * )( hash + 2 * n ))[ i ] = state [4 * i + 2 ];
2090- (( word64 * )( hash + 3 * n ))[ i ] = state [4 * i + 3 ];
2087+ writeUnalignedWord64 ( hash + 0 * n + i * 8 , state [4 * i + 0 ]) ;
2088+ writeUnalignedWord64 ( hash + 1 * n + i * 8 , state [4 * i + 1 ]) ;
2089+ writeUnalignedWord64 ( hash + 2 * n + i * 8 , state [4 * i + 2 ]) ;
2090+ writeUnalignedWord64 ( hash + 3 * n + i * 8 , state [4 * i + 3 ]) ;
20912091 }
20922092}
20932093
@@ -5155,10 +5155,10 @@ static int slhdsakey_hash_f_ti_x4(const byte* pk_seed, byte* addr, byte* node,
51555155 o = slhdsakey_shake256_set_seed_ha_x4 (state , pk_seed , addr , n );
51565156 SHAKE256_SET_TREE_INDEX (state , o , ti );
51575157 for (i = 0 ; i < n / 8 ; i ++ ) {
5158- state [o + 0 ] = (( word64 * )( node + 0 * n ))[ i ] ;
5159- state [o + 1 ] = (( word64 * )( node + 1 * n ))[ i ] ;
5160- state [o + 2 ] = (( word64 * )( node + 2 * n ))[ i ] ;
5161- state [o + 3 ] = (( word64 * )( node + 3 * n ))[ i ] ;
5158+ state [o + 0 ] = readUnalignedWord64 ( node + 0 * n + i * 8 ) ;
5159+ state [o + 1 ] = readUnalignedWord64 ( node + 1 * n + i * 8 ) ;
5160+ state [o + 2 ] = readUnalignedWord64 ( node + 2 * n + i * 8 ) ;
5161+ state [o + 3 ] = readUnalignedWord64 ( node + 3 * n + i * 8 ) ;
51625162 o += 4 ;
51635163 }
51645164 SHAKE256_SET_END_X4 (state , o );
@@ -5212,10 +5212,10 @@ static int slhdsakey_hash_h_ti_x4(const byte* pk_seed, byte* addr,
52125212 o = slhdsakey_shake256_set_seed_ha_x4 (state , pk_seed , addr , n );
52135213 SHAKE256_SET_TREE_INDEX (state , o , ti );
52145214 for (i = 0 ; i < 2 * n / 8 ; i ++ ) {
5215- state [o + 0 ] = (( const word64 * )( m + 0 * n ))[ i ] ;
5216- state [o + 1 ] = (( const word64 * )( m + 2 * n ))[ i ] ;
5217- state [o + 2 ] = (( const word64 * )( m + 4 * n ))[ i ] ;
5218- state [o + 3 ] = (( const word64 * )( m + 6 * n ))[ i ] ;
5215+ state [o + 0 ] = readUnalignedWord64 ( m + 0 * n + i * 8 ) ;
5216+ state [o + 1 ] = readUnalignedWord64 ( m + 2 * n + i * 8 ) ;
5217+ state [o + 2 ] = readUnalignedWord64 ( m + 4 * n + i * 8 ) ;
5218+ state [o + 3 ] = readUnalignedWord64 ( m + 6 * n + i * 8 ) ;
52195219 o += 4 ;
52205220 }
52215221 SHAKE256_SET_END_X4 (state , o );
@@ -6009,10 +6009,10 @@ static int slhdsakey_hash_f_ti4_x4(const byte* pk_seed, byte* addr,
60096009 o = slhdsakey_shake256_set_seed_ha_x4 (state , pk_seed , addr , n );
60106010 SHAKE256_SET_TREE_INDEX_IDX (state , o , ti );
60116011 for (i = 0 ; i < n / 8 ; i ++ ) {
6012- state [o + 0 ] = (( const word64 * )( sig_fors + 0 * so * n ))[ i ] ;
6013- state [o + 1 ] = (( const word64 * )( sig_fors + 1 * so * n ))[ i ] ;
6014- state [o + 2 ] = (( const word64 * )( sig_fors + 2 * so * n ))[ i ] ;
6015- state [o + 3 ] = (( const word64 * )( sig_fors + 3 * so * n ))[ i ] ;
6012+ state [o + 0 ] = readUnalignedWord64 ( sig_fors + 0 * so * n + i * 8 ) ;
6013+ state [o + 1 ] = readUnalignedWord64 ( sig_fors + 1 * so * n + i * 8 ) ;
6014+ state [o + 2 ] = readUnalignedWord64 ( sig_fors + 2 * so * n + i * 8 ) ;
6015+ state [o + 3 ] = readUnalignedWord64 ( sig_fors + 3 * so * n + i * 8 ) ;
60166016 o += 4 ;
60176017 }
60186018 SHAKE256_SET_END_X4 (state , o );
@@ -6074,11 +6074,12 @@ static int slhdsakey_hash_h_2_x4(const byte* pk_seed, byte* addr, byte* node,
60746074 for (i = 0 ; i < n / 8 ; i ++ ) {
60756075 for (j = 0 ; j < 4 ; j ++ ) {
60766076 if (bit [j ] == 0 ) {
6077- state [o + j ] = (( const word64 * )( node + j * n ))[ i ] ;
6077+ state [o + j ] = readUnalignedWord64 ( node + j * n + i * 8 ) ;
60786078 }
60796079 else {
60806080 state [o + j ] =
6081- ((const word64 * )(sig_fors + j * (word32 )so * n ))[i ];
6081+ readUnalignedWord64 (sig_fors + j *
6082+ (word32 )so * n + i * 8 );
60826083 }
60836084 }
60846085 o += 4 ;
@@ -6087,10 +6088,11 @@ static int slhdsakey_hash_h_2_x4(const byte* pk_seed, byte* addr, byte* node,
60876088 for (j = 0 ; j < 4 ; j ++ ) {
60886089 if (bit [j ] == 0 ) {
60896090 state [o + j ] =
6090- ((const word64 * )(sig_fors + j * (word32 )so * n ))[i ];
6091+ readUnalignedWord64 (sig_fors + j *
6092+ (word32 )so * n + i * 8 );
60916093 }
60926094 else {
6093- state [o + j ] = (( const word64 * )( node + j * n ))[ i ] ;
6095+ state [o + j ] = readUnalignedWord64 ( node + j * n + i * 8 ) ;
60946096 }
60956097 }
60966098 o += 4 ;
0 commit comments