summaryrefslogtreecommitdiff
path: root/lib/crypto/aesni.h
blob: 13d09d2d67621dccd9a26413fa26bedd1db65643 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
 * Copyright (C) 2008, Intel Corp.
 *    Author: Huang Ying <ying.huang@intel.com>
 *            Vinodh Gopal <vinodh.gopal@intel.com>
 *            Kahraman Akdemir
 *
 * Ported x86_64 version to x86:
 *    Author: Mathias Krause <minipli@googlemail.com>
 *
 * Modified for use in Samba by Justin Maggard <jmaggard@netgear.com>
 * and Jeremy Allison <jra@samba.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */

#ifndef LIB_CRYPTO_AESNI_H
#define LIB_CRYPTO_AESNI_H 1

#if defined(HAVE_AESNI_INTEL)

#define AES_MAX_KEYLENGTH      (15 * 16)
#define AES_MAX_KEYLENGTH_U32  (AES_MAX_KEYLENGTH / sizeof(uint32_t))

/*
 * Please ensure that the first two fields are 16-byte aligned
 * relative to the start of the structure, i.e., don't move them!
 */
struct crypto_aes_ctx {
	uint32_t key_enc[AES_MAX_KEYLENGTH_U32];
	uint32_t key_dec[AES_MAX_KEYLENGTH_U32];
	uint32_t key_length;
};

struct crypto_aesni_ctx {
	uint8_t _acc_ctx[sizeof(struct crypto_aes_ctx) + 16];
	struct crypto_aes_ctx *acc_ctx;
};

/*
 * These next 4 functions are actually implemented
 * in the assembly language file:
 * third_party/aesni-intel/aesni-intel_asm.c
 */

int aesni_set_key(struct crypto_aes_ctx *ctx,
		const uint8_t *in_key,
		unsigned int key_len);
void aesni_enc(struct crypto_aes_ctx *ctx, uint8_t *dst, const uint8_t *src);
void aesni_dec(struct crypto_aes_ctx *ctx, uint8_t *dst, const uint8_t *src);

#else /* #if defined(HAVE_AESNI_INTEL) */

/*
 * We need a dummy definition of struct crypto_aesni_ctx to allow compiles.
 */

struct crypto_aesni_ctx {
	int dummy;
};

#endif /* #if defined(HAVE_AESNI_INTEL) */

#endif /* LIB_CRYPTO_AESNI_H */