Skip to content

Commit fcedb70

Browse files
committed
Argon2 neon fix
1 parent a28a3cf commit fcedb70

2 files changed

Lines changed: 27 additions & 26 deletions

File tree

HashLib/src/Include/Simd/Argon2/Argon2FillBlockNeon_aarch64.inc

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,58 @@
11
// AArch64 NEON implementation of Argon2 FillBlock (BlaMka round function).
22
//
3-
// Reference: HashLib Argon2FillBlockSse2_x86_64.inc (FillBlock semantics);
4-
// libsodium blamka-round-neon.h (fBlaMka, vext diagonalize on AArch64).
3+
// Reference: jedisct1/libsodium crypto_pwhash/argon2/argon2-fill-block-neon.c,
4+
// crypto_pwhash/argon2/blamka-round-neon.h; HashLib Argon2FillBlockSse2_x86_64.inc.
55
//
66
// Expects AAPCS64: x0 = Left ptr, x1 = Right ptr, x2 = Current ptr, w3 = WithXor.
77
// Each pointer addresses 128 UInt64 (1024 bytes).
88
// Uses v0-v7 (A/B/C/D pairs), v16-v18 temps; caller-saved only, leaf nostackframe.
9-
// Stack: 2128 bytes (R_buf + Z_buf + AAPCS64 16-byte SP alignment padding).
9+
// Stack: 2128 bytes R_buf at [sp+64], Z_buf at [sp+1088], plus 16-byte SP pad.
1010
// x9 = R_buf, x11 = Z_buf during rounds; x2/w3 survive all loops.
1111
//
12-
// Steps (match SSE2):
12+
// Steps (same semantics as SSE2):
1313
// 1. R_buf = Left XOR Right
1414
// 2. Z_buf = copy(R_buf)
1515
// 3. Eight column rounds on Z_buf (128-byte slices)
1616
// 4. Eight row rounds on Z_buf (stride-16 qword access)
1717
// 5. Current = R_buf XOR Z_buf [XOR Current if WithXor <> 0]
18+
// Indexed loads/stores in steps 1/2/5: ldr/str qN, [xBase, x10].
19+
// Column/row slices: x12 = x11 + x10, then ldr/str qN, [x12, #imm].
20+
// Diagonalize uses vext #8 (blamka-round-neon.h), not SSE2 shufpd.
1821
//
1922
// Instruction encodings (for assembler compatibility):
2023
// FPC 3.2.2's inline assembler cannot encode AArch64 vector mnemonics
2124
// (subscripted vector regs require FPC 3.3+, and ldr/str/ldp with qN crash the
2225
// 3.2.2 assembler). Each such instruction is therefore emitted as its raw 32-bit
2326
// '.long' opcode, with the equivalent mnemonic in the trailing comment; only
24-
// stack/loop/branch/ret mnemonics stay as text.
27+
// add/mov/cmp/sub/cbz/b.lo/b/ret stay as text (never ldr/str/ldp with qN).
2528
//
26-
// Register map during G rounds:
29+
// Register map:
2730
// v0-v1 = A0, A1
2831
// v2-v3 = B0, B1
2932
// v4-v5 = C0, C1
3033
// v6-v7 = D0, D1
3134
// v16-v18 = fBlaMka / rotr temps
32-
// x9 = R_buf base
33-
// x11 = Z_buf base
34-
// x10 = loop offset
35+
// x9 = R_buf base ([sp+64])
36+
// x10 = loop byte offset (steps 1-5)
37+
// x11 = Z_buf base ([sp+1088])
38+
// x12 = Z slice pointer (column/row load/store)
3539
// w3 = WithXor (0 or 1)
3640
sub sp, sp, #2128
3741
add x9, sp, #64
3842
mov x10, #0
3943
.Largon2_xor_loop:
40-
ldr q0, [x0, x10]
41-
ldr q1, [x1, x10]
44+
.long 0x3cea6800 // ldr q0, [x0, x10]
45+
.long 0x3cea6821 // ldr q1, [x1, x10]
4246
.long 0x6e211c00 // eor v0.16b, v0.16b, v1.16b
43-
str q0, [x9, x10]
47+
.long 0x3caa6920 // str q0, [x9, x10]
4448
add x10, x10, #16
4549
cmp x10, #1024
4650
b.lo .Largon2_xor_loop
4751
add x11, sp, #1088
4852
mov x10, #0
4953
.Largon2_copy_loop:
50-
ldr q0, [x9, x10]
51-
str q0, [x11, x10]
54+
.long 0x3cea6920 // ldr q0, [x9, x10]
55+
.long 0x3caa6960 // str q0, [x11, x10]
5256
add x10, x10, #16
5357
cmp x10, #1024
5458
b.lo .Largon2_copy_loop
@@ -449,23 +453,23 @@
449453
cbz w3, .Largon2_final_noxor
450454
mov x10, #0
451455
.Largon2_final_xor_loop:
452-
ldr q0, [x9, x10]
453-
ldr q1, [x11, x10]
454-
ldr q2, [x2, x10]
456+
.long 0x3cea6920 // ldr q0, [x9, x10]
457+
.long 0x3cea6961 // ldr q1, [x11, x10]
458+
.long 0x3cea6842 // ldr q2, [x2, x10]
455459
.long 0x6e211c00 // eor v0.16b, v0.16b, v1.16b
456460
.long 0x6e221c00 // eor v0.16b, v0.16b, v2.16b
457-
str q0, [x2, x10]
461+
.long 0x3caa6840 // str q0, [x2, x10]
458462
add x10, x10, #16
459463
cmp x10, #1024
460464
b.lo .Largon2_final_xor_loop
461465
b .Largon2_epilogue
462466
.Largon2_final_noxor:
463467
mov x10, #0
464468
.Largon2_final_noxor_loop:
465-
ldr q0, [x9, x10]
466-
ldr q1, [x11, x10]
469+
.long 0x3cea6920 // ldr q0, [x9, x10]
470+
.long 0x3cea6961 // ldr q1, [x11, x10]
467471
.long 0x6e211c00 // eor v0.16b, v0.16b, v1.16b
468-
str q0, [x2, x10]
472+
.long 0x3caa6840 // str q0, [x2, x10]
469473
add x10, x10, #16
470474
cmp x10, #1024
471475
b.lo .Largon2_final_noxor_loop

HashLib/src/Include/Simd/Scrypt/ScryptSalsa8Neon_aarch64.inc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// AArch64 NEON implementation of fused XOR + Salsa20/8 on Percival-permuted data.
22
//
33
// Reference: Colin Percival, "Stronger Key Derivation via Sequential
4-
// Memory-Hard Functions" (2009), and the Tarsnap scrypt reference
5-
// implementation (crypto_scrypt_smix_sse2.c). The (i*5 mod 16) data permutation
4+
// Memory-Hard Functions" (2009); Tarsnap scrypt crypto_scrypt_smix_sse2.c;
5+
// HashLib ScryptSalsa8Sse2_x86_64.inc. The (i*5 mod 16) data permutation
66
// arranges each 16-word Salsa20 state into role-based diagonal order,
77
// enabling lane-parallel SIMD processing of column and row quarter-rounds
88
// with pshufd-based diagonalize/undiagonalize between them.
@@ -22,9 +22,6 @@
2222
// D ^= rotl(A+B,7); C ^= rotl(D+A,9); B ^= rotl(C+D,13); A ^= rotl(B+C,18)
2323
// Undiag: ins/pshufd B,$39; C,$4E; D,$93
2424
//
25-
// Reference (golden): HashLib ScryptSalsa8Sse2_x86_64.inc;
26-
// scripts/ref/scrypt-sse.c (Tarsnap excerpt).
27-
//
2825
// Instruction encodings (for assembler compatibility):
2926
// FPC 3.2.2's inline assembler cannot encode AArch64 vector mnemonics
3027
// (subscripted vector regs require FPC 3.3+, and ldr/str/ldp with qN crash the

0 commit comments

Comments
 (0)