Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/sys/crypto/armv8/armv8_crypto.h
39507 views
1
/*-
2
* Copyright (c) 2016 The FreeBSD Foundation
3
*
4
* This software was developed by Andrew Turner under
5
* sponsorship from the FreeBSD Foundation.
6
*
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions
9
* are met:
10
* 1. Redistributions of source code must retain the above copyright
11
* notice, this list of conditions and the following disclaimer.
12
* 2. Redistributions in binary form must reproduce the above copyright
13
* notice, this list of conditions and the following disclaimer in the
14
* documentation and/or other materials provided with the distribution.
15
*
16
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
17
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
20
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26
* SUCH DAMAGE.
27
*/
28
29
#ifndef _ARMV8_CRYPTO_H_
30
#define _ARMV8_CRYPTO_H_
31
32
#define AES256_ROUNDS 14
33
#define AES_SCHED_LEN ((AES256_ROUNDS + 1) * AES_BLOCK_LEN)
34
35
typedef struct {
36
uint32_t aes_key[AES_SCHED_LEN/4];
37
int aes_rounds;
38
} AES_key_t;
39
40
typedef union {
41
uint64_t u[2];
42
uint32_t d[4];
43
uint8_t c[16];
44
size_t t[16 / sizeof(size_t)];
45
} __uint128_val_t;
46
47
struct armv8_crypto_session {
48
AES_key_t enc_schedule;
49
AES_key_t dec_schedule;
50
AES_key_t xts_schedule;
51
__uint128_val_t Htable[16];
52
};
53
54
/* Prototypes for aesv8-armx.S */
55
void aes_v8_encrypt(uint8_t *in, uint8_t *out, const AES_key_t *key);
56
int aes_v8_set_encrypt_key(const unsigned char *userKey, const int bits, const AES_key_t *key);
57
int aes_v8_set_decrypt_key(const unsigned char *userKey, const int bits, const AES_key_t *key);
58
59
/* Prototypes for ghashv8-armx.S */
60
void gcm_init_v8(__uint128_val_t Htable[16], const uint64_t Xi[2]);
61
void gcm_gmult_v8(uint64_t Xi[2], const __uint128_val_t Htable[16]);
62
void gcm_ghash_v8(uint64_t Xi[2], const __uint128_val_t Htable[16], const uint8_t *inp, size_t len);
63
64
void armv8_aes_encrypt_cbc(const AES_key_t *key, size_t len,
65
struct crypto_buffer_cursor *fromc, struct crypto_buffer_cursor *toc,
66
const uint8_t iv[static AES_BLOCK_LEN]);
67
void armv8_aes_decrypt_cbc(const AES_key_t *, size_t,
68
struct crypto_buffer_cursor *fromc, struct crypto_buffer_cursor *toc,
69
const uint8_t[static AES_BLOCK_LEN]);
70
void armv8_aes_encrypt_gcm(AES_key_t *, size_t,
71
struct crypto_buffer_cursor *, struct crypto_buffer_cursor *,
72
size_t, const uint8_t *,
73
uint8_t tag[static GMAC_DIGEST_LEN],
74
const uint8_t[static AES_GCM_IV_LEN],
75
const __uint128_val_t *);
76
int armv8_aes_decrypt_gcm(AES_key_t *, size_t,
77
struct crypto_buffer_cursor *, struct crypto_buffer_cursor *,
78
size_t, const uint8_t *, const uint8_t tag[static GMAC_DIGEST_LEN],
79
const uint8_t[static AES_GCM_IV_LEN],
80
const __uint128_val_t *);
81
82
void armv8_aes_encrypt_xts(AES_key_t *, const void *, size_t,
83
struct crypto_buffer_cursor *, struct crypto_buffer_cursor *,
84
const uint8_t[AES_BLOCK_LEN]);
85
void armv8_aes_decrypt_xts(AES_key_t *, const void *, size_t,
86
struct crypto_buffer_cursor *, struct crypto_buffer_cursor *,
87
const uint8_t[AES_BLOCK_LEN]);
88
89
#endif /* _ARMV8_CRYPTO_H_ */
90
91