1 | /*
|
---|
2 | * Copyright 2022-2023 The OpenSSL Project Authors. All Rights Reserved.
|
---|
3 | *
|
---|
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
|
---|
8 | */
|
---|
9 |
|
---|
10 | #ifndef OSSL_SM4_PLATFORM_H
|
---|
11 | # define OSSL_SM4_PLATFORM_H
|
---|
12 | # pragma once
|
---|
13 |
|
---|
14 | # if defined(OPENSSL_CPUID_OBJ)
|
---|
15 | # if defined(__aarch64__)
|
---|
16 | # include "arm_arch.h"
|
---|
17 | extern unsigned int OPENSSL_arm_midr;
|
---|
18 | static inline int vpsm4_capable(void)
|
---|
19 | {
|
---|
20 | return (OPENSSL_armcap_P & ARMV8_CPUID) &&
|
---|
21 | (MIDR_IS_CPU_MODEL(OPENSSL_arm_midr, ARM_CPU_IMP_ARM, ARM_CPU_PART_V1) ||
|
---|
22 | MIDR_IS_CPU_MODEL(OPENSSL_arm_midr, ARM_CPU_IMP_ARM, ARM_CPU_PART_N1));
|
---|
23 | }
|
---|
24 | # if defined(VPSM4_ASM)
|
---|
25 | # define VPSM4_CAPABLE vpsm4_capable()
|
---|
26 | # endif
|
---|
27 | # define HWSM4_CAPABLE (OPENSSL_armcap_P & ARMV8_SM4)
|
---|
28 | # define HWSM4_set_encrypt_key sm4_v8_set_encrypt_key
|
---|
29 | # define HWSM4_set_decrypt_key sm4_v8_set_decrypt_key
|
---|
30 | # define HWSM4_encrypt sm4_v8_encrypt
|
---|
31 | # define HWSM4_decrypt sm4_v8_decrypt
|
---|
32 | # define HWSM4_cbc_encrypt sm4_v8_cbc_encrypt
|
---|
33 | # define HWSM4_ecb_encrypt sm4_v8_ecb_encrypt
|
---|
34 | # define HWSM4_ctr32_encrypt_blocks sm4_v8_ctr32_encrypt_blocks
|
---|
35 | # endif
|
---|
36 | # endif /* OPENSSL_CPUID_OBJ */
|
---|
37 |
|
---|
38 | # if defined(HWSM4_CAPABLE)
|
---|
39 | int HWSM4_set_encrypt_key(const unsigned char *userKey, SM4_KEY *key);
|
---|
40 | int HWSM4_set_decrypt_key(const unsigned char *userKey, SM4_KEY *key);
|
---|
41 | void HWSM4_encrypt(const unsigned char *in, unsigned char *out,
|
---|
42 | const SM4_KEY *key);
|
---|
43 | void HWSM4_decrypt(const unsigned char *in, unsigned char *out,
|
---|
44 | const SM4_KEY *key);
|
---|
45 | void HWSM4_cbc_encrypt(const unsigned char *in, unsigned char *out,
|
---|
46 | size_t length, const SM4_KEY *key,
|
---|
47 | unsigned char *ivec, const int enc);
|
---|
48 | void HWSM4_ecb_encrypt(const unsigned char *in, unsigned char *out,
|
---|
49 | size_t length, const SM4_KEY *key,
|
---|
50 | const int enc);
|
---|
51 | void HWSM4_ctr32_encrypt_blocks(const unsigned char *in, unsigned char *out,
|
---|
52 | size_t len, const void *key,
|
---|
53 | const unsigned char ivec[16]);
|
---|
54 | # endif /* HWSM4_CAPABLE */
|
---|
55 |
|
---|
56 | #ifdef VPSM4_CAPABLE
|
---|
57 | int vpsm4_set_encrypt_key(const unsigned char *userKey, SM4_KEY *key);
|
---|
58 | int vpsm4_set_decrypt_key(const unsigned char *userKey, SM4_KEY *key);
|
---|
59 | void vpsm4_encrypt(const unsigned char *in, unsigned char *out,
|
---|
60 | const SM4_KEY *key);
|
---|
61 | void vpsm4_decrypt(const unsigned char *in, unsigned char *out,
|
---|
62 | const SM4_KEY *key);
|
---|
63 | void vpsm4_cbc_encrypt(const unsigned char *in, unsigned char *out,
|
---|
64 | size_t length, const SM4_KEY *key,
|
---|
65 | unsigned char *ivec, const int enc);
|
---|
66 | void vpsm4_ecb_encrypt(const unsigned char *in, unsigned char *out,
|
---|
67 | size_t length, const SM4_KEY *key,
|
---|
68 | const int enc);
|
---|
69 | void vpsm4_ctr32_encrypt_blocks(const unsigned char *in, unsigned char *out,
|
---|
70 | size_t len, const void *key,
|
---|
71 | const unsigned char ivec[16]);
|
---|
72 | # endif /* VPSM4_CAPABLE */
|
---|
73 |
|
---|
74 |
|
---|
75 | #endif /* OSSL_SM4_PLATFORM_H */
|
---|