1 /*- 2 * Copyright (c) 2005-2006 Pawel Jakub Dawidek <pjd@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * $FreeBSD: src/sys/crypto/via/padlock.h,v 1.4 2006/07/28 14:46:19 pjd Exp $ 27 */ 28 29 #ifndef _PADLOCK_H_ 30 #define _PADLOCK_H_ 31 32 #include <sys/spinlock.h> 33 #include <opencrypto/cryptodev.h> 34 #include <crypto/rijndael/rijndael.h> 35 36 37 union padlock_cw { 38 uint64_t raw; 39 struct { 40 u_int round_count : 4; 41 u_int algorithm_type : 3; 42 u_int key_generation : 1; 43 u_int intermediate : 1; 44 u_int direction : 1; 45 u_int key_size : 2; 46 u_int filler0 : 20; 47 u_int filler1 : 32; 48 u_int filler2 : 32; 49 u_int filler3 : 32; 50 } __field; 51 }; 52 #define cw_round_count __field.round_count 53 #define cw_algorithm_type __field.algorithm_type 54 #define cw_key_generation __field.key_generation 55 #define cw_intermediate __field.intermediate 56 #define cw_direction __field.direction 57 #define cw_key_size __field.key_size 58 #define cw_filler0 __field.filler0 59 #define cw_filler1 __field.filler1 60 #define cw_filler2 __field.filler2 61 #define cw_filler3 __field.filler3 62 63 struct padlock_session { 64 union padlock_cw ses_cw __aligned(16); 65 uint32_t ses_ekey[4 * (RIJNDAEL_MAXNR + 1) + 4] __aligned(16); /* 128 bit aligned */ 66 uint32_t ses_dkey[4 * (RIJNDAEL_MAXNR + 1) + 4] __aligned(16); /* 128 bit aligned */ 67 uint8_t ses_iv[16] __aligned(16); /* 128 bit aligned */ 68 struct auth_hash *ses_axf; 69 uint8_t *ses_ictx; 70 uint8_t *ses_octx; 71 int ses_mlen; 72 int ses_used; 73 uint32_t ses_id; 74 TAILQ_ENTRY(padlock_session) ses_next; 75 void *ses_freeaddr; 76 } __aligned(16); 77 78 struct padlock_softc { 79 int32_t sc_cid; 80 uint32_t sc_sid; 81 int32_t sc_rng_ticks; 82 struct callout sc_rng_co; 83 TAILQ_HEAD(padlock_sessions_head, padlock_session) sc_sessions; 84 struct spinlock sc_sessions_lock; 85 }; 86 87 #define PADLOCK_ALIGN(p) (void *)(roundup2((uintptr_t)(p), 16)) 88 89 int padlock_cipher_setup(struct padlock_session *ses, 90 struct cryptoini *encini); 91 int padlock_cipher_process(struct padlock_session *ses, 92 struct cryptodesc *enccrd, struct cryptop *crp); 93 int padlock_hash_setup(struct padlock_session *ses, 94 struct cryptoini *macini); 95 int padlock_hash_process(struct padlock_session *ses, 96 struct cryptodesc *maccrd, struct cryptop *crp); 97 void padlock_hash_free(struct padlock_session *ses); 98 void padlock_rng_init(struct padlock_softc *sc); 99 void padlock_rng_uninit(struct padlock_softc *sc); 100 101 #endif /* !_PADLOCK_H_ */ 102