]>
git.ipfire.org Git - thirdparty/openssl.git/blob - include/crypto/sm4_platform.h
2 * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #ifndef OSSL_SM4_PLATFORM_H
11 # define OSSL_SM4_PLATFORM_H
14 # if defined(OPENSSL_CPUID_OBJ)
15 # if (defined(__arm__) || defined(__arm) || defined(__aarch64__))
16 # include "arm_arch.h"
17 # if __ARM_MAX_ARCH__>=8
18 extern unsigned int OPENSSL_arm_midr
;
19 static inline int vpsm4_capable(void)
21 return (OPENSSL_armcap_P
& ARMV8_CPUID
) &&
22 (MIDR_IS_CPU_MODEL(OPENSSL_arm_midr
, ARM_CPU_IMP_ARM
, ARM_CPU_PART_V1
) ||
23 MIDR_IS_CPU_MODEL(OPENSSL_arm_midr
, ARM_CPU_IMP_ARM
, ARM_CPU_PART_N1
));
25 # if defined(VPSM4_ASM)
26 # define VPSM4_CAPABLE vpsm4_capable()
28 # define HWSM4_CAPABLE (OPENSSL_armcap_P & ARMV8_SM4)
29 # define HWSM4_set_encrypt_key sm4_v8_set_encrypt_key
30 # define HWSM4_set_decrypt_key sm4_v8_set_decrypt_key
31 # define HWSM4_encrypt sm4_v8_encrypt
32 # define HWSM4_decrypt sm4_v8_decrypt
33 # define HWSM4_cbc_encrypt sm4_v8_cbc_encrypt
34 # define HWSM4_ecb_encrypt sm4_v8_ecb_encrypt
35 # define HWSM4_ctr32_encrypt_blocks sm4_v8_ctr32_encrypt_blocks
38 # endif /* OPENSSL_CPUID_OBJ */
40 # if defined(HWSM4_CAPABLE)
41 int HWSM4_set_encrypt_key(const unsigned char *userKey
, SM4_KEY
*key
);
42 int HWSM4_set_decrypt_key(const unsigned char *userKey
, SM4_KEY
*key
);
43 void HWSM4_encrypt(const unsigned char *in
, unsigned char *out
,
45 void HWSM4_decrypt(const unsigned char *in
, unsigned char *out
,
47 void HWSM4_cbc_encrypt(const unsigned char *in
, unsigned char *out
,
48 size_t length
, const SM4_KEY
*key
,
49 unsigned char *ivec
, const int enc
);
50 void HWSM4_ecb_encrypt(const unsigned char *in
, unsigned char *out
,
51 size_t length
, const SM4_KEY
*key
,
53 void HWSM4_ctr32_encrypt_blocks(const unsigned char *in
, unsigned char *out
,
54 size_t len
, const void *key
,
55 const unsigned char ivec
[16]);
56 # endif /* HWSM4_CAPABLE */
59 int vpsm4_set_encrypt_key(const unsigned char *userKey
, SM4_KEY
*key
);
60 int vpsm4_set_decrypt_key(const unsigned char *userKey
, SM4_KEY
*key
);
61 void vpsm4_encrypt(const unsigned char *in
, unsigned char *out
,
63 void vpsm4_decrypt(const unsigned char *in
, unsigned char *out
,
65 void vpsm4_cbc_encrypt(const unsigned char *in
, unsigned char *out
,
66 size_t length
, const SM4_KEY
*key
,
67 unsigned char *ivec
, const int enc
);
68 void vpsm4_ecb_encrypt(const unsigned char *in
, unsigned char *out
,
69 size_t length
, const SM4_KEY
*key
,
71 void vpsm4_ctr32_encrypt_blocks(const unsigned char *in
, unsigned char *out
,
72 size_t len
, const void *key
,
73 const unsigned char ivec
[16]);
74 # endif /* VPSM4_CAPABLE */
77 #endif /* OSSL_SM4_PLATFORM_H */