1104476Ssam/* $OpenBSD: xform.c,v 1.16 2001/08/28 12:20:43 ben Exp $ */ 2139825Simp/*- 3104476Ssam * The authors of this code are John Ioannidis (ji@tla.org), 4247061Spjd * Angelos D. Keromytis (kermit@csd.uch.gr), 5247061Spjd * Niels Provos (provos@physnet.uni-hamburg.de) and 6247061Spjd * Damien Miller (djm@mindrot.org). 7104476Ssam * 8104476Ssam * This code was written by John Ioannidis for BSD/OS in Athens, Greece, 9104476Ssam * in November 1995. 10104476Ssam * 11104476Ssam * Ported to OpenBSD and NetBSD, with additional transforms, in December 1996, 12104476Ssam * by Angelos D. Keromytis. 13104476Ssam * 14104476Ssam * Additional transforms and features in 1997 and 1998 by Angelos D. Keromytis 15104476Ssam * and Niels Provos. 16104476Ssam * 17104476Ssam * Additional features in 1999 by Angelos D. Keromytis. 18104476Ssam * 19247061Spjd * AES XTS implementation in 2008 by Damien Miller 20247061Spjd * 21104476Ssam * Copyright (C) 1995, 1996, 1997, 1998, 1999 by John Ioannidis, 22104476Ssam * Angelos D. Keromytis and Niels Provos. 23104476Ssam * 24104476Ssam * Copyright (C) 2001, Angelos D. Keromytis. 25104476Ssam * 26247061Spjd * Copyright (C) 2008, Damien Miller 27275732Sjmg * Copyright (c) 2014 The FreeBSD Foundation 28275732Sjmg * All rights reserved. 29247061Spjd * 30275732Sjmg * Portions of this software were developed by John-Mark Gurney 31275732Sjmg * under sponsorship of the FreeBSD Foundation and 32275732Sjmg * Rubicon Communications, LLC (Netgate). 33275732Sjmg * 34104476Ssam * Permission to use, copy, and modify this software with or without fee 35104476Ssam * is hereby granted, provided that this entire notice is included in 36104476Ssam * all copies of any software which is or includes a copy or 37104476Ssam * modification of this software. 38104476Ssam * You may use this code under the GNU public license if you so wish. Please 39104476Ssam * contribute changes back to the authors under this freer than GPL license 40104476Ssam * so that we may further the use of strong encryption without limitations to 41104476Ssam * all. 42104476Ssam * 43104476Ssam * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR 44104476Ssam * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY 45104476Ssam * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE 46104476Ssam * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR 47104476Ssam * PURPOSE. 48104476Ssam */ 49104476Ssam 50116191Sobrien#include <sys/cdefs.h> 51116191Sobrien__FBSDID("$FreeBSD: releng/11.0/sys/opencrypto/xform_skipjack.c 292963 2015-12-30 22:43:07Z allanjude $"); 52116191Sobrien 53104476Ssam#include <opencrypto/skipjack.h> 54292963Sallanjude#include <opencrypto/xform_enc.h> 55104476Ssam 56104476Ssamstatic int skipjack_setkey(u_int8_t **, u_int8_t *, int); 57104476Ssamstatic void skipjack_encrypt(caddr_t, u_int8_t *); 58104476Ssamstatic void skipjack_decrypt(caddr_t, u_int8_t *); 59104476Ssamstatic void skipjack_zerokey(u_int8_t **); 60104476Ssam 61104476Ssam/* Encryption instances */ 62104476Ssamstruct enc_xform enc_xform_skipjack = { 63104476Ssam CRYPTO_SKIPJACK_CBC, "Skipjack", 64285336Sgnn SKIPJACK_BLOCK_LEN, SKIPJACK_BLOCK_LEN, SKIPJACK_MIN_KEY, 65285336Sgnn SKIPJACK_MAX_KEY, 66104476Ssam skipjack_encrypt, 67275732Sjmg skipjack_decrypt, skipjack_setkey, 68213068Spjd skipjack_zerokey, 69275732Sjmg NULL, 70104476Ssam}; 71104476Ssam 72104476Ssam/* 73104476Ssam * Encryption wrapper routines. 74104476Ssam */ 75104476Ssamstatic void 76104476Ssamskipjack_encrypt(caddr_t key, u_int8_t *blk) 77104476Ssam{ 78104476Ssam skipjack_forwards(blk, blk, (u_int8_t **) key); 79104476Ssam} 80104476Ssam 81104476Ssamstatic void 82104476Ssamskipjack_decrypt(caddr_t key, u_int8_t *blk) 83104476Ssam{ 84104476Ssam skipjack_backwards(blk, blk, (u_int8_t **) key); 85104476Ssam} 86104476Ssam 87104476Ssamstatic int 88104476Ssamskipjack_setkey(u_int8_t **sched, u_int8_t *key, int len) 89104476Ssam{ 90104476Ssam int err; 91104476Ssam 92104476Ssam /* NB: allocate all the memory that's needed at once */ 93292963Sallanjude *sched = KMALLOC(10 * (sizeof(u_int8_t *) + 0x100), 94104476Ssam M_CRYPTO_DATA, M_NOWAIT|M_ZERO); 95104476Ssam if (*sched != NULL) { 96104476Ssam u_int8_t** key_tables = (u_int8_t**) *sched; 97104476Ssam u_int8_t* table = (u_int8_t*) &key_tables[10]; 98104476Ssam int k; 99104476Ssam 100104476Ssam for (k = 0; k < 10; k++) { 101104476Ssam key_tables[k] = table; 102104476Ssam table += 0x100; 103104476Ssam } 104104476Ssam subkey_table_gen(key, (u_int8_t **) *sched); 105104476Ssam err = 0; 106104476Ssam } else 107104476Ssam err = ENOMEM; 108104476Ssam return err; 109104476Ssam} 110104476Ssam 111104476Ssamstatic void 112104476Ssamskipjack_zerokey(u_int8_t **sched) 113104476Ssam{ 114104476Ssam bzero(*sched, 10 * (sizeof(u_int8_t *) + 0x100)); 115292963Sallanjude KFREE(*sched, M_CRYPTO_DATA); 116104476Ssam *sched = NULL; 117104476Ssam} 118