YPC  0.2.0
sm4_aes.h
1 #pragma once
2 #include "ypc/corecommon/crypto/aes_gcm_traits.h"
3 #include <cstdint>
4 
5 namespace ypc {
6 namespace crypto {
7 
8 #define INITIALIZATION_VECTOR_SIZE 12
9 class sm4_aes {
10 public:
11  static inline uint32_t get_mac_code_size() { return 16; }
12  static inline uint32_t get_cipher_size(uint32_t data_size) {
13  return data_size + INITIALIZATION_VECTOR_SIZE;
14  }
15  static inline uint32_t get_data_size(uint32_t cipher_size) {
16  return cipher_size - INITIALIZATION_VECTOR_SIZE;
17  }
18  static inline uint32_t get_key_size() { return 16; }
19 
20  static uint32_t encrypt_with_prefix(const uint8_t *key, uint32_t key_size,
21  const uint8_t *data, uint32_t data_size,
22  uint32_t prefix, uint8_t *cipher,
23  uint32_t cipher_size, uint8_t *out_mac);
24 
25  static uint32_t decrypt_with_prefix(const uint8_t *key, uint32_t key_size,
26  const uint8_t *cipher,
27  uint32_t cipher_size, uint32_t prefix,
28  uint8_t *data, uint32_t data_size,
29  const uint8_t *in_mac);
30 };
31 template <> struct aes_gcm_traits<sm4_aes> {
32  constexpr static bool value = true;
33 };
34 }
35 }
ypc::crypto::aes_gcm_traits
Definition: aes_gcm_traits.h:6
ypc::crypto::sm4_aes
Definition: sm4_aes.h:9