quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

aegis128l_soft.c (1831B)


      1 #include <errno.h>
      2 #include <stddef.h>
      3 #include <stdint.h>
      4 #include <stdlib.h>
      5 #include <string.h>
      6 
      7 #include "core.h"
      8 #include "crypto_aead_aegis128l.h"
      9 #include "crypto_verify_16.h"
     10 #include "crypto_verify_32.h"
     11 #include "export.h"
     12 #include "utils.h"
     13 
     14 #include "private/common.h"
     15 
     16 #include "crypto_aead_aegis128l.h"
     17 #include "private/softaes.h"
     18 
     19 #if 1
     20 
     21 #include "aegis128l_soft.h"
     22 
     23 #define AES_BLOCK_LENGTH 16
     24 
     25 typedef SoftAesBlock aes_block_t;
     26 #define AES_BLOCK_XOR(A, B)       softaes_block_xor((A), (B))
     27 #define AES_BLOCK_AND(A, B)       softaes_block_and((A), (B))
     28 #define AES_BLOCK_LOAD(A)         softaes_block_load(A)
     29 #define AES_BLOCK_LOAD_64x2(A, B) softaes_block_load64x2((A), (B))
     30 #define AES_BLOCK_STORE(A, B)     softaes_block_store((A), (B))
     31 #define AES_ENC(A, B)             softaes_block_encrypt((A), (B))
     32 
     33 static inline void
     34 aegis128l_update(aes_block_t *const state, const aes_block_t d1, const aes_block_t d2)
     35 {
     36     aes_block_t tmp;
     37 
     38     tmp      = state[7];
     39     state[7] = AES_ENC(state[6], state[7]);
     40     state[6] = AES_ENC(state[5], state[6]);
     41     state[5] = AES_ENC(state[4], state[5]);
     42     state[4] = AES_ENC(state[3], state[4]);
     43     state[3] = AES_ENC(state[2], state[3]);
     44     state[2] = AES_ENC(state[1], state[2]);
     45     state[1] = AES_ENC(state[0], state[1]);
     46     state[0] = AES_ENC(tmp, state[0]);
     47 
     48     state[0] = AES_BLOCK_XOR(state[0], d1);
     49     state[4] = AES_BLOCK_XOR(state[4], d2);
     50 }
     51 
     52 #include "aegis128l_common.h"
     53 
     54 struct aegis128l_implementation aegis128l_soft_implementation = { SODIUM_C99(.encrypt_detached =)
     55                                                                       encrypt_detached,
     56                                                                   SODIUM_C99(.decrypt_detached =)
     57                                                                       decrypt_detached };
     58 
     59 #endif