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