1160582Spjd/*- 2160582Spjd * Copyright (c) 2005-2006 Pawel Jakub Dawidek <pjd@FreeBSD.org> 3160582Spjd * All rights reserved. 4160582Spjd * 5160582Spjd * Redistribution and use in source and binary forms, with or without 6160582Spjd * modification, are permitted provided that the following conditions 7160582Spjd * are met: 8160582Spjd * 1. Redistributions of source code must retain the above copyright 9160582Spjd * notice, this list of conditions and the following disclaimer. 10160582Spjd * 2. Redistributions in binary form must reproduce the above copyright 11160582Spjd * notice, this list of conditions and the following disclaimer in the 12160582Spjd * documentation and/or other materials provided with the distribution. 13160674Spjd * 14160582Spjd * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 15160582Spjd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16160582Spjd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17160582Spjd * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 18160582Spjd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19160582Spjd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20160582Spjd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21160582Spjd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22160582Spjd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23160582Spjd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24160582Spjd * SUCH DAMAGE. 25160582Spjd * 26160582Spjd * $FreeBSD$ 27160582Spjd */ 28160582Spjd 29160582Spjd#ifndef _PADLOCK_H_ 30160582Spjd#define _PADLOCK_H_ 31160582Spjd 32160582Spjd#include <opencrypto/cryptodev.h> 33160582Spjd#include <crypto/rijndael/rijndael.h> 34160582Spjd 35208834Skib#if defined(__i386__) 36208834Skib#include <machine/npx.h> 37208834Skib#elif defined(__amd64__) 38208834Skib#include <machine/fpu.h> 39208834Skib#endif 40208834Skib 41160582Spjdunion padlock_cw { 42160582Spjd uint64_t raw; 43160582Spjd struct { 44160582Spjd u_int round_count : 4; 45160582Spjd u_int algorithm_type : 3; 46160582Spjd u_int key_generation : 1; 47160582Spjd u_int intermediate : 1; 48160582Spjd u_int direction : 1; 49160582Spjd u_int key_size : 2; 50160582Spjd u_int filler0 : 20; 51160582Spjd u_int filler1 : 32; 52160582Spjd u_int filler2 : 32; 53160582Spjd u_int filler3 : 32; 54160582Spjd } __field; 55160582Spjd}; 56160582Spjd#define cw_round_count __field.round_count 57160582Spjd#define cw_algorithm_type __field.algorithm_type 58160582Spjd#define cw_key_generation __field.key_generation 59160582Spjd#define cw_intermediate __field.intermediate 60160582Spjd#define cw_direction __field.direction 61160582Spjd#define cw_key_size __field.key_size 62160582Spjd#define cw_filler0 __field.filler0 63160582Spjd#define cw_filler1 __field.filler1 64160582Spjd#define cw_filler2 __field.filler2 65160582Spjd#define cw_filler3 __field.filler3 66160582Spjd 67160582Spjdstruct padlock_session { 68160582Spjd union padlock_cw ses_cw __aligned(16); 69160582Spjd uint32_t ses_ekey[4 * (RIJNDAEL_MAXNR + 1) + 4] __aligned(16); /* 128 bit aligned */ 70160582Spjd uint32_t ses_dkey[4 * (RIJNDAEL_MAXNR + 1) + 4] __aligned(16); /* 128 bit aligned */ 71160582Spjd uint8_t ses_iv[16] __aligned(16); /* 128 bit aligned */ 72160582Spjd struct auth_hash *ses_axf; 73160582Spjd uint8_t *ses_ictx; 74160582Spjd uint8_t *ses_octx; 75160582Spjd int ses_mlen; 76160582Spjd int ses_used; 77160582Spjd uint32_t ses_id; 78160582Spjd TAILQ_ENTRY(padlock_session) ses_next; 79230426Skib struct fpu_kern_ctx *ses_fpu_ctx; 80160582Spjd}; 81160582Spjd 82160784Spjd#define PADLOCK_ALIGN(p) (void *)(roundup2((uintptr_t)(p), 16)) 83160582Spjd 84160582Spjdint padlock_cipher_setup(struct padlock_session *ses, 85160582Spjd struct cryptoini *encini); 86160582Spjdint padlock_cipher_process(struct padlock_session *ses, 87160582Spjd struct cryptodesc *enccrd, struct cryptop *crp); 88160582Spjdint padlock_hash_setup(struct padlock_session *ses, 89160582Spjd struct cryptoini *macini); 90160582Spjdint padlock_hash_process(struct padlock_session *ses, 91160582Spjd struct cryptodesc *maccrd, struct cryptop *crp); 92160582Spjdvoid padlock_hash_free(struct padlock_session *ses); 93160582Spjd 94160582Spjd#endif /* !_PADLOCK_H_ */ 95