luajitos

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

crypto_core.h (2099B)


      1 /*
      2  * crypto_core.h - Core AES and Serpent implementations (shared)
      3  */
      4 
      5 #ifndef CRYPTO_CORE_H
      6 #define CRYPTO_CORE_H
      7 
      8 #include <stdint.h>
      9 #include <stdlib.h>
     10 #include <immintrin.h>
     11 
     12 // AES-256-GCM structures
     13 typedef struct {
     14     __m128i round_keys[15];
     15     int nr;
     16 } aes256_key_schedule;
     17 
     18 typedef struct {
     19     aes256_key_schedule key_schedule;
     20     __m128i H;
     21     __m128i H_powers[8];
     22 } aes256_gcm_context;
     23 
     24 // Serpent structures
     25 typedef struct {
     26     uint32_t subkeys[33][4];
     27 } serpent_key_schedule;
     28 
     29 typedef struct {
     30     serpent_key_schedule key_schedule;
     31     __m128i H;
     32     __m128i H_powers[8];
     33 } serpent_gcm_context;
     34 
     35 // AES-256-GCM functions
     36 int aes256_gcm_init(aes256_gcm_context *ctx, const uint8_t *key);
     37 int aes256_gcm_encrypt(aes256_gcm_context *ctx, const uint8_t *iv, size_t iv_len,
     38                        const uint8_t *aad, size_t aad_len,
     39                        const uint8_t *plaintext, size_t pt_len,
     40                        uint8_t *ciphertext, uint8_t *tag, size_t tag_len);
     41 int aes256_gcm_decrypt(aes256_gcm_context *ctx, const uint8_t *iv, size_t iv_len,
     42                        const uint8_t *aad, size_t aad_len,
     43                        const uint8_t *ciphertext, size_t ct_len,
     44                        const uint8_t *tag, size_t tag_len, uint8_t *plaintext);
     45 
     46 // Serpent-256-GCM functions
     47 int serpent_gcm_init(serpent_gcm_context *ctx, const uint8_t *key);
     48 int serpent_gcm_encrypt(serpent_gcm_context *ctx, const uint8_t *iv, size_t iv_len,
     49                         const uint8_t *aad, size_t aad_len,
     50                         const uint8_t *plaintext, size_t pt_len,
     51                         uint8_t *ciphertext, uint8_t *tag, size_t tag_len);
     52 int serpent_gcm_decrypt(serpent_gcm_context *ctx, const uint8_t *iv, size_t iv_len,
     53                         const uint8_t *aad, size_t aad_len,
     54                         const uint8_t *ciphertext, size_t ct_len,
     55                         const uint8_t *tag, size_t tag_len, uint8_t *plaintext);
     56 
     57 // CPU feature detection
     58 extern int crypto_has_aesni;
     59 extern int crypto_has_pclmulqdq;
     60 void crypto_detect_features(void);
     61 
     62 #endif // CRYPTO_CORE_H