186d7f5d3SJohn Marino /*- 286d7f5d3SJohn Marino * Copyright (c) 2005-2006 Pawel Jakub Dawidek <pjd@FreeBSD.org> 386d7f5d3SJohn Marino * All rights reserved. 486d7f5d3SJohn Marino * 586d7f5d3SJohn Marino * Redistribution and use in source and binary forms, with or without 686d7f5d3SJohn Marino * modification, are permitted provided that the following conditions 786d7f5d3SJohn Marino * are met: 886d7f5d3SJohn Marino * 1. Redistributions of source code must retain the above copyright 986d7f5d3SJohn Marino * notice, this list of conditions and the following disclaimer. 1086d7f5d3SJohn Marino * 2. Redistributions in binary form must reproduce the above copyright 1186d7f5d3SJohn Marino * notice, this list of conditions and the following disclaimer in the 1286d7f5d3SJohn Marino * documentation and/or other materials provided with the distribution. 1386d7f5d3SJohn Marino * 1486d7f5d3SJohn Marino * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 1586d7f5d3SJohn Marino * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1686d7f5d3SJohn Marino * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1786d7f5d3SJohn Marino * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 1886d7f5d3SJohn Marino * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1986d7f5d3SJohn Marino * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2086d7f5d3SJohn Marino * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2186d7f5d3SJohn Marino * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2286d7f5d3SJohn Marino * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2386d7f5d3SJohn Marino * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2486d7f5d3SJohn Marino * SUCH DAMAGE. 2586d7f5d3SJohn Marino * 2686d7f5d3SJohn Marino * $FreeBSD: src/sys/crypto/via/padlock.h,v 1.4 2006/07/28 14:46:19 pjd Exp $ 2786d7f5d3SJohn Marino */ 2886d7f5d3SJohn Marino 2986d7f5d3SJohn Marino #ifndef _PADLOCK_H_ 3086d7f5d3SJohn Marino #define _PADLOCK_H_ 3186d7f5d3SJohn Marino 3286d7f5d3SJohn Marino #include <sys/spinlock.h> 3386d7f5d3SJohn Marino #include <opencrypto/cryptodev.h> 3486d7f5d3SJohn Marino #include <crypto/rijndael/rijndael.h> 3586d7f5d3SJohn Marino 3686d7f5d3SJohn Marino 3786d7f5d3SJohn Marino union padlock_cw { 3886d7f5d3SJohn Marino uint64_t raw; 3986d7f5d3SJohn Marino struct { 4086d7f5d3SJohn Marino u_int round_count : 4; 4186d7f5d3SJohn Marino u_int algorithm_type : 3; 4286d7f5d3SJohn Marino u_int key_generation : 1; 4386d7f5d3SJohn Marino u_int intermediate : 1; 4486d7f5d3SJohn Marino u_int direction : 1; 4586d7f5d3SJohn Marino u_int key_size : 2; 4686d7f5d3SJohn Marino u_int filler0 : 20; 4786d7f5d3SJohn Marino u_int filler1 : 32; 4886d7f5d3SJohn Marino u_int filler2 : 32; 4986d7f5d3SJohn Marino u_int filler3 : 32; 5086d7f5d3SJohn Marino } __field; 5186d7f5d3SJohn Marino }; 5286d7f5d3SJohn Marino #define cw_round_count __field.round_count 5386d7f5d3SJohn Marino #define cw_algorithm_type __field.algorithm_type 5486d7f5d3SJohn Marino #define cw_key_generation __field.key_generation 5586d7f5d3SJohn Marino #define cw_intermediate __field.intermediate 5686d7f5d3SJohn Marino #define cw_direction __field.direction 5786d7f5d3SJohn Marino #define cw_key_size __field.key_size 5886d7f5d3SJohn Marino #define cw_filler0 __field.filler0 5986d7f5d3SJohn Marino #define cw_filler1 __field.filler1 6086d7f5d3SJohn Marino #define cw_filler2 __field.filler2 6186d7f5d3SJohn Marino #define cw_filler3 __field.filler3 6286d7f5d3SJohn Marino 6386d7f5d3SJohn Marino struct padlock_session { 6486d7f5d3SJohn Marino union padlock_cw ses_cw __aligned(16); 6586d7f5d3SJohn Marino uint32_t ses_ekey[4 * (RIJNDAEL_MAXNR + 1) + 4] __aligned(16); /* 128 bit aligned */ 6686d7f5d3SJohn Marino uint32_t ses_dkey[4 * (RIJNDAEL_MAXNR + 1) + 4] __aligned(16); /* 128 bit aligned */ 6786d7f5d3SJohn Marino uint8_t ses_iv[16] __aligned(16); /* 128 bit aligned */ 6886d7f5d3SJohn Marino struct auth_hash *ses_axf; 6986d7f5d3SJohn Marino uint8_t *ses_ictx; 7086d7f5d3SJohn Marino uint8_t *ses_octx; 7186d7f5d3SJohn Marino int ses_mlen; 7286d7f5d3SJohn Marino int ses_used; 7386d7f5d3SJohn Marino uint32_t ses_id; 7486d7f5d3SJohn Marino TAILQ_ENTRY(padlock_session) ses_next; 7586d7f5d3SJohn Marino void *ses_freeaddr; 7686d7f5d3SJohn Marino } __aligned(16); 7786d7f5d3SJohn Marino 7886d7f5d3SJohn Marino struct padlock_softc { 7986d7f5d3SJohn Marino int32_t sc_cid; 8086d7f5d3SJohn Marino uint32_t sc_sid; 8186d7f5d3SJohn Marino int32_t sc_rng_ticks; 8286d7f5d3SJohn Marino struct callout sc_rng_co; 8386d7f5d3SJohn Marino TAILQ_HEAD(padlock_sessions_head, padlock_session) sc_sessions; 8486d7f5d3SJohn Marino struct spinlock sc_sessions_lock; 8586d7f5d3SJohn Marino }; 8686d7f5d3SJohn Marino 8786d7f5d3SJohn Marino #define PADLOCK_ALIGN(p) (void *)(roundup2((uintptr_t)(p), 16)) 8886d7f5d3SJohn Marino 8986d7f5d3SJohn Marino int padlock_cipher_setup(struct padlock_session *ses, 9086d7f5d3SJohn Marino struct cryptoini *encini); 9186d7f5d3SJohn Marino int padlock_cipher_process(struct padlock_session *ses, 9286d7f5d3SJohn Marino struct cryptodesc *enccrd, struct cryptop *crp); 9386d7f5d3SJohn Marino int padlock_hash_setup(struct padlock_session *ses, 9486d7f5d3SJohn Marino struct cryptoini *macini); 9586d7f5d3SJohn Marino int padlock_hash_process(struct padlock_session *ses, 9686d7f5d3SJohn Marino struct cryptodesc *maccrd, struct cryptop *crp); 9786d7f5d3SJohn Marino void padlock_hash_free(struct padlock_session *ses); 9886d7f5d3SJohn Marino void padlock_rng_init(struct padlock_softc *sc); 9986d7f5d3SJohn Marino void padlock_rng_uninit(struct padlock_softc *sc); 10086d7f5d3SJohn Marino 10186d7f5d3SJohn Marino #endif /* !_PADLOCK_H_ */ 102