Skip to content

Commit f5c52dc

Browse files
committed
Update Charm
1 parent 695191f commit f5c52dc

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

src/charm.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ static void permute(uint32_t st[12])
8080

8181
static void permute(uint32_t st[12])
8282
{
83+
#ifdef __aarch64__
84+
const uint8x16_t rhoEast2 = { 11, 8, 9, 10, 15, 12, 13, 14,
85+
3, 0, 1, 2, 7, 4, 5, 6 };
86+
#endif
8387
uint32x4_t a, b, c, d, e, f;
8488
int r;
8589

@@ -104,9 +108,14 @@ static void permute(uint32_t st[12])
104108
a = veorq_u32(a, e);
105109
d = veorq_u32(b, d);
106110
c = veorq_u32(c, f);
107-
f = vextq_u32(c, c, 2);
108111
b = ROL32in128(d, 1);
112+
#ifdef __aarch64__
113+
c = vreinterpretq_u32_u8(vqtbl1q_u8(vreinterpretq_u8_u32(c),
114+
rhoEast2));
115+
#else
116+
f = vextq_u32(c, c, 2);
109117
c = ROL32in128(f, 8);
118+
#endif
110119
}
111120
vst1q_u32((uint32_t *) (void *) &st[0], a);
112121
vst1q_u32((uint32_t *) (void *) &st[4], b);
@@ -178,6 +187,9 @@ static inline void xor128(void *out, const void *in)
178187
_mm_storeu_si128((__m128i *) out,
179188
_mm_xor_si128(_mm_loadu_si128((const __m128i *) out),
180189
_mm_loadu_si128((const __m128i *) in)));
190+
#elif defined(__ARM_NEON) || defined(__aarch64__)
191+
vst1q_u8((uint8_t *) out, veorq_u8(vld1q_u8((const uint8_t *) out),
192+
vld1q_u8((const uint8_t *) in)));
181193
#else
182194
unsigned char *out_ = (unsigned char *) out;
183195
const unsigned char *in_ = (const unsigned char *) in;
@@ -213,7 +225,11 @@ static inline void squeeze_permute(uint32_t st[12], unsigned char dst[16])
213225

214226
void uc_state_init(uint32_t st[12], const unsigned char key[32], const unsigned char iv[16])
215227
{
216-
memcpy(&st[0], iv, 16);
228+
if (iv != NULL) {
229+
memcpy(&st[0], iv, 16);
230+
} else {
231+
memset(&st[0], 0, 16);
232+
}
217233
memcpy(&st[4], key, 32);
218234
endian_swap_all(st);
219235
permute(st);

0 commit comments

Comments
 (0)