diff options
author | Guillaume Le Vaillant <glv@posteo.net> | 2023-06-10 14:09:37 +0200 |
---|---|---|
committer | Guillaume Le Vaillant <glv@posteo.net> | 2023-06-10 14:09:37 +0200 |
commit | 62a99d3936825ead445e1820f35b0a1c318ebcce (patch) | |
tree | a57397b2aaa9237d5673ed52ea307c64b9f92f2d | |
parent | bf3fa4b953063722cefd33783826f0b205795953 (diff) |
Fix optimized Chacha and Salsa core functions for newer ECL
-rw-r--r-- | src/opt/ecl/c-functions.lisp | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/src/opt/ecl/c-functions.lisp b/src/opt/ecl/c-functions.lisp index eb5142b..5e622cf 100644 --- a/src/opt/ecl/c-functions.lisp +++ b/src/opt/ecl/c-functions.lisp @@ -4,25 +4,16 @@ #+(and ecl ironclad-assembly) (progn - (ffi:clines " -#define ROTL32(v, c) \\ + (declaim (inline x-chacha-core)) + (defun x-chacha-core (n-rounds buffer state) + (ffi:clines "#define ROTL32(v, c) \\ (((v) << (c)) | ((v) >> (32 - (c)))) #define CHACHA_QUARTER_ROUND(a, b, c, d) \\ x[a] += x[b]; x[d] = ROTL32(x[d] ^ x[a], 16); \\ x[c] += x[d]; x[b] = ROTL32(x[b] ^ x[c], 12); \\ x[a] += x[b]; x[d] = ROTL32(x[d] ^ x[a], 8); \\ - x[c] += x[d]; x[b] = ROTL32(x[b] ^ x[c], 7); - -#define SALSA_QUARTER_ROUND(a, b, c, d) \\ - x[a] ^= ROTL32(x[d] + x[c], 7); \\ - x[b] ^= ROTL32(x[a] + x[d], 9); \\ - x[c] ^= ROTL32(x[b] + x[a], 13); \\ - x[d] ^= ROTL32(x[c] + x[b], 18); -") - - (declaim (inline x-chacha-core)) - (defun x-chacha-core (n-rounds buffer state) + x[c] += x[d]; x[b] = ROTL32(x[b] ^ x[c], 7);") (ffi:c-inline (n-rounds buffer state) (:unsigned-int t t) :void @@ -63,6 +54,14 @@ for(i = 0; i < 16; i++) (declaim (inline x-salsa-core)) (defun x-salsa-core (n-rounds buffer state) + (ffi:clines "#define ROTL32(v, c) \\ + (((v) << (c)) | ((v) >> (32 - (c)))) + +#define SALSA_QUARTER_ROUND(a, b, c, d) \\ + x[a] ^= ROTL32(x[d] + x[c], 7); \\ + x[b] ^= ROTL32(x[a] + x[d], 9); \\ + x[c] ^= ROTL32(x[b] + x[a], 13); \\ + x[d] ^= ROTL32(x[c] + x[b], 18);") (ffi:c-inline (n-rounds buffer state) (:unsigned-int t t) :void |