xform_sha2.c revision 285336
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: head/sys/opencrypto/xform.c 285336 2015-07-09 18:16:35Z gnn $"); 52116191Sobrien 53104476Ssam#include <sys/param.h> 54104476Ssam#include <sys/systm.h> 55104476Ssam#include <sys/malloc.h> 56104476Ssam#include <sys/sysctl.h> 57104476Ssam#include <sys/errno.h> 58104476Ssam#include <sys/time.h> 59104476Ssam#include <sys/kernel.h> 60104476Ssam#include <machine/cpu.h> 61104476Ssam 62104476Ssam#include <crypto/blowfish/blowfish.h> 63104476Ssam#include <crypto/des/des.h> 64143423Sume#include <crypto/rijndael/rijndael.h> 65169425Sgnn#include <crypto/camellia/camellia.h> 66104476Ssam#include <crypto/sha1.h> 67104476Ssam 68104476Ssam#include <opencrypto/cast.h> 69104476Ssam#include <opencrypto/deflate.h> 70104476Ssam#include <opencrypto/rmd160.h> 71104476Ssam#include <opencrypto/skipjack.h> 72104476Ssam 73104476Ssam#include <sys/md5.h> 74104476Ssam 75104476Ssam#include <opencrypto/cryptodev.h> 76104476Ssam#include <opencrypto/xform.h> 77104476Ssam 78213068Spjdstatic int null_setkey(u_int8_t **, u_int8_t *, int); 79104476Ssamstatic int des1_setkey(u_int8_t **, u_int8_t *, int); 80104476Ssamstatic int des3_setkey(u_int8_t **, u_int8_t *, int); 81104476Ssamstatic int blf_setkey(u_int8_t **, u_int8_t *, int); 82104476Ssamstatic int cast5_setkey(u_int8_t **, u_int8_t *, int); 83104476Ssamstatic int skipjack_setkey(u_int8_t **, u_int8_t *, int); 84104476Ssamstatic int rijndael128_setkey(u_int8_t **, u_int8_t *, int); 85275732Sjmgstatic int aes_icm_setkey(u_int8_t **, u_int8_t *, int); 86213068Spjdstatic int aes_xts_setkey(u_int8_t **, u_int8_t *, int); 87169425Sgnnstatic int cml_setkey(u_int8_t **, u_int8_t *, int); 88213068Spjd 89213068Spjdstatic void null_encrypt(caddr_t, u_int8_t *); 90104476Ssamstatic void des1_encrypt(caddr_t, u_int8_t *); 91104476Ssamstatic void des3_encrypt(caddr_t, u_int8_t *); 92104476Ssamstatic void blf_encrypt(caddr_t, u_int8_t *); 93104476Ssamstatic void cast5_encrypt(caddr_t, u_int8_t *); 94104476Ssamstatic void skipjack_encrypt(caddr_t, u_int8_t *); 95104476Ssamstatic void rijndael128_encrypt(caddr_t, u_int8_t *); 96213068Spjdstatic void aes_xts_encrypt(caddr_t, u_int8_t *); 97169425Sgnnstatic void cml_encrypt(caddr_t, u_int8_t *); 98213068Spjd 99213068Spjdstatic void null_decrypt(caddr_t, u_int8_t *); 100104476Ssamstatic void des1_decrypt(caddr_t, u_int8_t *); 101104476Ssamstatic void des3_decrypt(caddr_t, u_int8_t *); 102104476Ssamstatic void blf_decrypt(caddr_t, u_int8_t *); 103104476Ssamstatic void cast5_decrypt(caddr_t, u_int8_t *); 104104476Ssamstatic void skipjack_decrypt(caddr_t, u_int8_t *); 105104476Ssamstatic void rijndael128_decrypt(caddr_t, u_int8_t *); 106213068Spjdstatic void aes_xts_decrypt(caddr_t, u_int8_t *); 107169425Sgnnstatic void cml_decrypt(caddr_t, u_int8_t *); 108213068Spjd 109275732Sjmgstatic void aes_icm_crypt(caddr_t, u_int8_t *); 110275732Sjmg 111213068Spjdstatic void null_zerokey(u_int8_t **); 112104476Ssamstatic void des1_zerokey(u_int8_t **); 113104476Ssamstatic void des3_zerokey(u_int8_t **); 114104476Ssamstatic void blf_zerokey(u_int8_t **); 115104476Ssamstatic void cast5_zerokey(u_int8_t **); 116104476Ssamstatic void skipjack_zerokey(u_int8_t **); 117104476Ssamstatic void rijndael128_zerokey(u_int8_t **); 118275732Sjmgstatic void aes_icm_zerokey(u_int8_t **); 119213068Spjdstatic void aes_xts_zerokey(u_int8_t **); 120169425Sgnnstatic void cml_zerokey(u_int8_t **); 121104476Ssam 122275732Sjmgstatic void aes_icm_reinit(caddr_t, u_int8_t *); 123213068Spjdstatic void aes_xts_reinit(caddr_t, u_int8_t *); 124275732Sjmgstatic void aes_gcm_reinit(caddr_t, u_int8_t *); 125213068Spjd 126104476Ssamstatic void null_init(void *); 127275732Sjmgstatic void null_reinit(void *ctx, const u_int8_t *buf, u_int16_t len); 128275732Sjmgstatic int null_update(void *, const u_int8_t *, u_int16_t); 129104476Ssamstatic void null_final(u_int8_t *, void *); 130275732Sjmgstatic int MD5Update_int(void *, const u_int8_t *, u_int16_t); 131104476Ssamstatic void SHA1Init_int(void *); 132275732Sjmgstatic int SHA1Update_int(void *, const u_int8_t *, u_int16_t); 133104476Ssamstatic void SHA1Final_int(u_int8_t *, void *); 134275732Sjmgstatic int RMD160Update_int(void *, const u_int8_t *, u_int16_t); 135275732Sjmgstatic int SHA256Update_int(void *, const u_int8_t *, u_int16_t); 136275732Sjmgstatic int SHA384Update_int(void *, const u_int8_t *, u_int16_t); 137275732Sjmgstatic int SHA512Update_int(void *, const u_int8_t *, u_int16_t); 138104476Ssam 139104476Ssamstatic u_int32_t deflate_compress(u_int8_t *, u_int32_t, u_int8_t **); 140104476Ssamstatic u_int32_t deflate_decompress(u_int8_t *, u_int32_t, u_int8_t **); 141104476Ssam 142275732Sjmg#define AESICM_BLOCKSIZE 16 143275732Sjmg 144275732Sjmgstruct aes_icm_ctx { 145275732Sjmg u_int32_t ac_ek[4*(RIJNDAEL_MAXNR + 1)]; 146275732Sjmg /* ac_block is initalized to IV */ 147275732Sjmg u_int8_t ac_block[AESICM_BLOCKSIZE]; 148275732Sjmg int ac_nr; 149275732Sjmg}; 150275732Sjmg 151104476SsamMALLOC_DEFINE(M_XDATA, "xform", "xform data buffers"); 152104476Ssam 153104476Ssam/* Encryption instances */ 154104476Ssamstruct enc_xform enc_xform_null = { 155104476Ssam CRYPTO_NULL_CBC, "NULL", 156104476Ssam /* NB: blocksize of 4 is to generate a properly aligned ESP header */ 157285336Sgnn NULL_BLOCK_LEN, NULL_BLOCK_LEN, NULL_MIN_KEY, NULL_MAX_KEY, 158104476Ssam null_encrypt, 159104476Ssam null_decrypt, 160104476Ssam null_setkey, 161104476Ssam null_zerokey, 162275732Sjmg NULL, 163104476Ssam}; 164104476Ssam 165104476Ssamstruct enc_xform enc_xform_des = { 166104476Ssam CRYPTO_DES_CBC, "DES", 167285336Sgnn DES_BLOCK_LEN, DES_BLOCK_LEN, DES_MIN_KEY, DES_MAX_KEY, 168104476Ssam des1_encrypt, 169104476Ssam des1_decrypt, 170104476Ssam des1_setkey, 171104476Ssam des1_zerokey, 172275732Sjmg NULL, 173104476Ssam}; 174104476Ssam 175104476Ssamstruct enc_xform enc_xform_3des = { 176104476Ssam CRYPTO_3DES_CBC, "3DES", 177285336Sgnn DES3_BLOCK_LEN, DES3_BLOCK_LEN, TRIPLE_DES_MIN_KEY, 178285336Sgnn TRIPLE_DES_MAX_KEY, 179104476Ssam des3_encrypt, 180104476Ssam des3_decrypt, 181104476Ssam des3_setkey, 182213068Spjd des3_zerokey, 183275732Sjmg NULL, 184104476Ssam}; 185104476Ssam 186104476Ssamstruct enc_xform enc_xform_blf = { 187104476Ssam CRYPTO_BLF_CBC, "Blowfish", 188285336Sgnn BLOWFISH_BLOCK_LEN, BLOWFISH_BLOCK_LEN, BLOWFISH_MIN_KEY, 189285336Sgnn BLOWFISH_MAX_KEY, 190104476Ssam blf_encrypt, 191104476Ssam blf_decrypt, 192104476Ssam blf_setkey, 193213068Spjd blf_zerokey, 194275732Sjmg NULL, 195104476Ssam}; 196104476Ssam 197104476Ssamstruct enc_xform enc_xform_cast5 = { 198104476Ssam CRYPTO_CAST_CBC, "CAST-128", 199285336Sgnn CAST128_BLOCK_LEN, CAST128_BLOCK_LEN, CAST_MIN_KEY, CAST_MAX_KEY, 200104476Ssam cast5_encrypt, 201104476Ssam cast5_decrypt, 202104476Ssam cast5_setkey, 203213068Spjd cast5_zerokey, 204275732Sjmg NULL, 205104476Ssam}; 206104476Ssam 207104476Ssamstruct enc_xform enc_xform_skipjack = { 208104476Ssam CRYPTO_SKIPJACK_CBC, "Skipjack", 209285336Sgnn SKIPJACK_BLOCK_LEN, SKIPJACK_BLOCK_LEN, SKIPJACK_MIN_KEY, 210285336Sgnn SKIPJACK_MAX_KEY, 211104476Ssam skipjack_encrypt, 212275732Sjmg skipjack_decrypt, skipjack_setkey, 213213068Spjd skipjack_zerokey, 214275732Sjmg NULL, 215104476Ssam}; 216104476Ssam 217104476Ssamstruct enc_xform enc_xform_rijndael128 = { 218104476Ssam CRYPTO_RIJNDAEL128_CBC, "Rijndael-128/AES", 219285336Sgnn RIJNDAEL128_BLOCK_LEN, RIJNDAEL128_BLOCK_LEN, RIJNDAEL_MIN_KEY, 220285336Sgnn RIJNDAEL_MAX_KEY, 221104476Ssam rijndael128_encrypt, 222104476Ssam rijndael128_decrypt, 223104476Ssam rijndael128_setkey, 224104476Ssam rijndael128_zerokey, 225275732Sjmg NULL, 226104476Ssam}; 227104476Ssam 228275732Sjmgstruct enc_xform enc_xform_aes_icm = { 229275732Sjmg CRYPTO_AES_ICM, "AES-ICM", 230285336Sgnn RIJNDAEL128_BLOCK_LEN, RIJNDAEL128_BLOCK_LEN, AES_MIN_KEY, AES_MAX_KEY, 231275732Sjmg aes_icm_crypt, 232275732Sjmg aes_icm_crypt, 233275732Sjmg aes_icm_setkey, 234275732Sjmg rijndael128_zerokey, 235275732Sjmg aes_icm_reinit, 236275732Sjmg}; 237275732Sjmg 238275732Sjmgstruct enc_xform enc_xform_aes_nist_gcm = { 239275732Sjmg CRYPTO_AES_NIST_GCM_16, "AES-GCM", 240285336Sgnn AES_MIN_BLOCK_LEN, AES_IV_LEN, AES_MIN_KEY, AES_MAX_KEY, 241275732Sjmg aes_icm_crypt, 242275732Sjmg aes_icm_crypt, 243275732Sjmg aes_icm_setkey, 244275732Sjmg aes_icm_zerokey, 245275732Sjmg aes_gcm_reinit, 246275732Sjmg}; 247275732Sjmg 248275732Sjmgstruct enc_xform enc_xform_aes_nist_gmac = { 249275732Sjmg CRYPTO_AES_NIST_GMAC, "AES-GMAC", 250285336Sgnn AES_MIN_BLOCK_LEN, AES_IV_LEN, AES_MIN_KEY, AES_MAX_KEY, 251275732Sjmg NULL, 252275732Sjmg NULL, 253275732Sjmg NULL, 254275732Sjmg NULL, 255275732Sjmg NULL, 256275732Sjmg}; 257275732Sjmg 258213068Spjdstruct enc_xform enc_xform_aes_xts = { 259213068Spjd CRYPTO_AES_XTS, "AES-XTS", 260285336Sgnn AES_MIN_BLOCK_LEN, AES_XTS_IV_LEN, AES_XTS_MIN_KEY, AES_XTS_MAX_KEY, 261213068Spjd aes_xts_encrypt, 262213068Spjd aes_xts_decrypt, 263213068Spjd aes_xts_setkey, 264213068Spjd aes_xts_zerokey, 265213068Spjd aes_xts_reinit 266213068Spjd}; 267213068Spjd 268104476Ssamstruct enc_xform enc_xform_arc4 = { 269104476Ssam CRYPTO_ARC4, "ARC4", 270285336Sgnn ARC4_BLOCK_LEN, ARC4_IV_LEN, ARC4_MIN_KEY, ARC4_MAX_KEY, 271104476Ssam NULL, 272104476Ssam NULL, 273104476Ssam NULL, 274104476Ssam NULL, 275275732Sjmg NULL, 276104476Ssam}; 277104476Ssam 278169425Sgnnstruct enc_xform enc_xform_camellia = { 279169425Sgnn CRYPTO_CAMELLIA_CBC, "Camellia", 280285336Sgnn CAMELLIA_BLOCK_LEN, CAMELLIA_BLOCK_LEN, CAMELLIA_MIN_KEY, 281285336Sgnn CAMELLIA_MAX_KEY, 282169425Sgnn cml_encrypt, 283169425Sgnn cml_decrypt, 284169425Sgnn cml_setkey, 285169425Sgnn cml_zerokey, 286275732Sjmg NULL, 287169425Sgnn}; 288169425Sgnn 289104476Ssam/* Authentication instances */ 290275732Sjmgstruct auth_hash auth_hash_null = { /* NB: context isn't used */ 291104476Ssam CRYPTO_NULL_HMAC, "NULL-HMAC", 292285336Sgnn NULL_HMAC_KEY_LEN, NULL_HASH_LEN, sizeof(int), NULL_HMAC_BLOCK_LEN, 293275732Sjmg null_init, null_reinit, null_reinit, null_update, null_final 294104476Ssam}; 295104476Ssam 296158703Spjdstruct auth_hash auth_hash_hmac_md5 = { 297104476Ssam CRYPTO_MD5_HMAC, "HMAC-MD5", 298285336Sgnn MD5_HMAC_KEY_LEN, MD5_HASH_LEN, sizeof(MD5_CTX), MD5_HMAC_BLOCK_LEN, 299275732Sjmg (void (*) (void *)) MD5Init, NULL, NULL, MD5Update_int, 300104476Ssam (void (*) (u_int8_t *, void *)) MD5Final 301104476Ssam}; 302104476Ssam 303158703Spjdstruct auth_hash auth_hash_hmac_sha1 = { 304104476Ssam CRYPTO_SHA1_HMAC, "HMAC-SHA1", 305285336Sgnn SHA1_HMAC_KEY_LEN, SHA1_HASH_LEN, sizeof(SHA1_CTX), SHA1_HMAC_BLOCK_LEN, 306275732Sjmg SHA1Init_int, NULL, NULL, SHA1Update_int, SHA1Final_int 307104476Ssam}; 308104476Ssam 309158703Spjdstruct auth_hash auth_hash_hmac_ripemd_160 = { 310104476Ssam CRYPTO_RIPEMD160_HMAC, "HMAC-RIPEMD-160", 311285336Sgnn RIPEMD160_HMAC_KEY_LEN, RIPEMD160_HASH_LEN, sizeof(RMD160_CTX), 312285336Sgnn RIPEMD160_HMAC_BLOCK_LEN, 313275732Sjmg (void (*)(void *)) RMD160Init, NULL, NULL, RMD160Update_int, 314104476Ssam (void (*)(u_int8_t *, void *)) RMD160Final 315104476Ssam}; 316104476Ssam 317104476Ssamstruct auth_hash auth_hash_key_md5 = { 318213065Spjd CRYPTO_MD5_KPDK, "Keyed MD5", 319285336Sgnn NULL_HMAC_KEY_LEN, MD5_KPDK_HASH_LEN, sizeof(MD5_CTX), 0, 320275732Sjmg (void (*)(void *)) MD5Init, NULL, NULL, MD5Update_int, 321104476Ssam (void (*)(u_int8_t *, void *)) MD5Final 322104476Ssam}; 323104476Ssam 324104476Ssamstruct auth_hash auth_hash_key_sha1 = { 325104476Ssam CRYPTO_SHA1_KPDK, "Keyed SHA1", 326285336Sgnn NULL_HMAC_KEY_LEN, SHA1_KPDK_HASH_LEN, sizeof(SHA1_CTX), 0, 327275732Sjmg SHA1Init_int, NULL, NULL, SHA1Update_int, SHA1Final_int 328104476Ssam}; 329104476Ssam 330104476Ssamstruct auth_hash auth_hash_hmac_sha2_256 = { 331158703Spjd CRYPTO_SHA2_256_HMAC, "HMAC-SHA2-256", 332285336Sgnn SHA2_256_HMAC_KEY_LEN, SHA2_256_HASH_LEN, sizeof(SHA256_CTX), 333285336Sgnn SHA2_256_HMAC_BLOCK_LEN, 334275732Sjmg (void (*)(void *)) SHA256_Init, NULL, NULL, SHA256Update_int, 335104476Ssam (void (*)(u_int8_t *, void *)) SHA256_Final 336104476Ssam}; 337104476Ssam 338104476Ssamstruct auth_hash auth_hash_hmac_sha2_384 = { 339158703Spjd CRYPTO_SHA2_384_HMAC, "HMAC-SHA2-384", 340285336Sgnn SHA2_384_HMAC_KEY_LEN, SHA2_384_HASH_LEN, sizeof(SHA384_CTX), 341285336Sgnn SHA2_384_HMAC_BLOCK_LEN, 342275732Sjmg (void (*)(void *)) SHA384_Init, NULL, NULL, SHA384Update_int, 343104476Ssam (void (*)(u_int8_t *, void *)) SHA384_Final 344104476Ssam}; 345104476Ssam 346104476Ssamstruct auth_hash auth_hash_hmac_sha2_512 = { 347158703Spjd CRYPTO_SHA2_512_HMAC, "HMAC-SHA2-512", 348285336Sgnn SHA2_512_HMAC_KEY_LEN, SHA2_512_HASH_LEN, sizeof(SHA512_CTX), 349285336Sgnn SHA2_512_HMAC_BLOCK_LEN, 350275732Sjmg (void (*)(void *)) SHA512_Init, NULL, NULL, SHA512Update_int, 351104476Ssam (void (*)(u_int8_t *, void *)) SHA512_Final 352104476Ssam}; 353104476Ssam 354275732Sjmgstruct auth_hash auth_hash_nist_gmac_aes_128 = { 355275732Sjmg CRYPTO_AES_128_NIST_GMAC, "GMAC-AES-128", 356285336Sgnn AES_128_HMAC_KEY_LEN, AES_HASH_LEN, sizeof(struct aes_gmac_ctx), 357285336Sgnn GMAC_BLOCK_LEN, 358275732Sjmg (void (*)(void *)) AES_GMAC_Init, 359275732Sjmg (void (*)(void *, const u_int8_t *, u_int16_t)) AES_GMAC_Setkey, 360275732Sjmg (void (*)(void *, const u_int8_t *, u_int16_t)) AES_GMAC_Reinit, 361275732Sjmg (int (*)(void *, const u_int8_t *, u_int16_t)) AES_GMAC_Update, 362275732Sjmg (void (*)(u_int8_t *, void *)) AES_GMAC_Final 363275732Sjmg}; 364275732Sjmg 365275732Sjmgstruct auth_hash auth_hash_nist_gmac_aes_192 = { 366275732Sjmg CRYPTO_AES_192_NIST_GMAC, "GMAC-AES-192", 367285336Sgnn AES_192_HMAC_KEY_LEN, AES_HASH_LEN, sizeof(struct aes_gmac_ctx), 368285336Sgnn GMAC_BLOCK_LEN, 369275732Sjmg (void (*)(void *)) AES_GMAC_Init, 370275732Sjmg (void (*)(void *, const u_int8_t *, u_int16_t)) AES_GMAC_Setkey, 371275732Sjmg (void (*)(void *, const u_int8_t *, u_int16_t)) AES_GMAC_Reinit, 372275732Sjmg (int (*)(void *, const u_int8_t *, u_int16_t)) AES_GMAC_Update, 373275732Sjmg (void (*)(u_int8_t *, void *)) AES_GMAC_Final 374275732Sjmg}; 375275732Sjmg 376275732Sjmgstruct auth_hash auth_hash_nist_gmac_aes_256 = { 377275732Sjmg CRYPTO_AES_256_NIST_GMAC, "GMAC-AES-256", 378285336Sgnn AES_256_HMAC_KEY_LEN, AES_HASH_LEN, sizeof(struct aes_gmac_ctx), 379285336Sgnn GMAC_BLOCK_LEN, 380275732Sjmg (void (*)(void *)) AES_GMAC_Init, 381275732Sjmg (void (*)(void *, const u_int8_t *, u_int16_t)) AES_GMAC_Setkey, 382275732Sjmg (void (*)(void *, const u_int8_t *, u_int16_t)) AES_GMAC_Reinit, 383275732Sjmg (int (*)(void *, const u_int8_t *, u_int16_t)) AES_GMAC_Update, 384275732Sjmg (void (*)(u_int8_t *, void *)) AES_GMAC_Final 385275732Sjmg}; 386275732Sjmg 387104476Ssam/* Compression instance */ 388104476Ssamstruct comp_algo comp_algo_deflate = { 389104476Ssam CRYPTO_DEFLATE_COMP, "Deflate", 390104476Ssam 90, deflate_compress, 391104476Ssam deflate_decompress 392104476Ssam}; 393104476Ssam 394104476Ssam/* 395104476Ssam * Encryption wrapper routines. 396104476Ssam */ 397104476Ssamstatic void 398104476Ssamnull_encrypt(caddr_t key, u_int8_t *blk) 399104476Ssam{ 400104476Ssam} 401104476Ssamstatic void 402104476Ssamnull_decrypt(caddr_t key, u_int8_t *blk) 403104476Ssam{ 404104476Ssam} 405104476Ssamstatic int 406104476Ssamnull_setkey(u_int8_t **sched, u_int8_t *key, int len) 407104476Ssam{ 408104476Ssam *sched = NULL; 409104476Ssam return 0; 410104476Ssam} 411104476Ssamstatic void 412104476Ssamnull_zerokey(u_int8_t **sched) 413104476Ssam{ 414104476Ssam *sched = NULL; 415104476Ssam} 416104476Ssam 417104476Ssamstatic void 418104476Ssamdes1_encrypt(caddr_t key, u_int8_t *blk) 419104476Ssam{ 420104476Ssam des_cblock *cb = (des_cblock *) blk; 421104476Ssam des_key_schedule *p = (des_key_schedule *) key; 422104476Ssam 423104476Ssam des_ecb_encrypt(cb, cb, p[0], DES_ENCRYPT); 424104476Ssam} 425104476Ssam 426104476Ssamstatic void 427104476Ssamdes1_decrypt(caddr_t key, u_int8_t *blk) 428104476Ssam{ 429104476Ssam des_cblock *cb = (des_cblock *) blk; 430104476Ssam des_key_schedule *p = (des_key_schedule *) key; 431104476Ssam 432104476Ssam des_ecb_encrypt(cb, cb, p[0], DES_DECRYPT); 433104476Ssam} 434104476Ssam 435104476Ssamstatic int 436104476Ssamdes1_setkey(u_int8_t **sched, u_int8_t *key, int len) 437104476Ssam{ 438104476Ssam des_key_schedule *p; 439104476Ssam int err; 440104476Ssam 441184205Sdes p = malloc(sizeof (des_key_schedule), 442104476Ssam M_CRYPTO_DATA, M_NOWAIT|M_ZERO); 443104476Ssam if (p != NULL) { 444104476Ssam des_set_key((des_cblock *) key, p[0]); 445104476Ssam err = 0; 446104476Ssam } else 447104476Ssam err = ENOMEM; 448104476Ssam *sched = (u_int8_t *) p; 449104476Ssam return err; 450104476Ssam} 451104476Ssam 452104476Ssamstatic void 453104476Ssamdes1_zerokey(u_int8_t **sched) 454104476Ssam{ 455104476Ssam bzero(*sched, sizeof (des_key_schedule)); 456184205Sdes free(*sched, M_CRYPTO_DATA); 457104476Ssam *sched = NULL; 458104476Ssam} 459104476Ssam 460104476Ssamstatic void 461104476Ssamdes3_encrypt(caddr_t key, u_int8_t *blk) 462104476Ssam{ 463104476Ssam des_cblock *cb = (des_cblock *) blk; 464104476Ssam des_key_schedule *p = (des_key_schedule *) key; 465104476Ssam 466104476Ssam des_ecb3_encrypt(cb, cb, p[0], p[1], p[2], DES_ENCRYPT); 467104476Ssam} 468104476Ssam 469104476Ssamstatic void 470104476Ssamdes3_decrypt(caddr_t key, u_int8_t *blk) 471104476Ssam{ 472104476Ssam des_cblock *cb = (des_cblock *) blk; 473104476Ssam des_key_schedule *p = (des_key_schedule *) key; 474104476Ssam 475104476Ssam des_ecb3_encrypt(cb, cb, p[0], p[1], p[2], DES_DECRYPT); 476104476Ssam} 477104476Ssam 478104476Ssamstatic int 479104476Ssamdes3_setkey(u_int8_t **sched, u_int8_t *key, int len) 480104476Ssam{ 481104476Ssam des_key_schedule *p; 482104476Ssam int err; 483104476Ssam 484184205Sdes p = malloc(3*sizeof (des_key_schedule), 485104476Ssam M_CRYPTO_DATA, M_NOWAIT|M_ZERO); 486104476Ssam if (p != NULL) { 487104476Ssam des_set_key((des_cblock *)(key + 0), p[0]); 488104476Ssam des_set_key((des_cblock *)(key + 8), p[1]); 489104476Ssam des_set_key((des_cblock *)(key + 16), p[2]); 490104476Ssam err = 0; 491104476Ssam } else 492104476Ssam err = ENOMEM; 493104476Ssam *sched = (u_int8_t *) p; 494104476Ssam return err; 495104476Ssam} 496104476Ssam 497104476Ssamstatic void 498104476Ssamdes3_zerokey(u_int8_t **sched) 499104476Ssam{ 500104476Ssam bzero(*sched, 3*sizeof (des_key_schedule)); 501184205Sdes free(*sched, M_CRYPTO_DATA); 502104476Ssam *sched = NULL; 503104476Ssam} 504104476Ssam 505104476Ssamstatic void 506104476Ssamblf_encrypt(caddr_t key, u_int8_t *blk) 507104476Ssam{ 508104476Ssam BF_LONG t[2]; 509104476Ssam 510104476Ssam memcpy(t, blk, sizeof (t)); 511104476Ssam t[0] = ntohl(t[0]); 512104476Ssam t[1] = ntohl(t[1]); 513104476Ssam /* NB: BF_encrypt expects the block in host order! */ 514104476Ssam BF_encrypt(t, (BF_KEY *) key); 515104476Ssam t[0] = htonl(t[0]); 516104476Ssam t[1] = htonl(t[1]); 517104476Ssam memcpy(blk, t, sizeof (t)); 518104476Ssam} 519104476Ssam 520104476Ssamstatic void 521104476Ssamblf_decrypt(caddr_t key, u_int8_t *blk) 522104476Ssam{ 523104476Ssam BF_LONG t[2]; 524104476Ssam 525104476Ssam memcpy(t, blk, sizeof (t)); 526104476Ssam t[0] = ntohl(t[0]); 527104476Ssam t[1] = ntohl(t[1]); 528104476Ssam /* NB: BF_decrypt expects the block in host order! */ 529104476Ssam BF_decrypt(t, (BF_KEY *) key); 530104476Ssam t[0] = htonl(t[0]); 531104476Ssam t[1] = htonl(t[1]); 532104476Ssam memcpy(blk, t, sizeof (t)); 533104476Ssam} 534104476Ssam 535104476Ssamstatic int 536104476Ssamblf_setkey(u_int8_t **sched, u_int8_t *key, int len) 537104476Ssam{ 538104476Ssam int err; 539104476Ssam 540184205Sdes *sched = malloc(sizeof(BF_KEY), 541104476Ssam M_CRYPTO_DATA, M_NOWAIT|M_ZERO); 542104476Ssam if (*sched != NULL) { 543104476Ssam BF_set_key((BF_KEY *) *sched, len, key); 544104476Ssam err = 0; 545104476Ssam } else 546104476Ssam err = ENOMEM; 547104476Ssam return err; 548104476Ssam} 549104476Ssam 550104476Ssamstatic void 551104476Ssamblf_zerokey(u_int8_t **sched) 552104476Ssam{ 553104476Ssam bzero(*sched, sizeof(BF_KEY)); 554184205Sdes free(*sched, M_CRYPTO_DATA); 555104476Ssam *sched = NULL; 556104476Ssam} 557104476Ssam 558104476Ssamstatic void 559104476Ssamcast5_encrypt(caddr_t key, u_int8_t *blk) 560104476Ssam{ 561104476Ssam cast_encrypt((cast_key *) key, blk, blk); 562104476Ssam} 563104476Ssam 564104476Ssamstatic void 565104476Ssamcast5_decrypt(caddr_t key, u_int8_t *blk) 566104476Ssam{ 567104476Ssam cast_decrypt((cast_key *) key, blk, blk); 568104476Ssam} 569104476Ssam 570104476Ssamstatic int 571104476Ssamcast5_setkey(u_int8_t **sched, u_int8_t *key, int len) 572104476Ssam{ 573104476Ssam int err; 574104476Ssam 575184205Sdes *sched = malloc(sizeof(cast_key), M_CRYPTO_DATA, M_NOWAIT|M_ZERO); 576104476Ssam if (*sched != NULL) { 577104476Ssam cast_setkey((cast_key *)*sched, key, len); 578104476Ssam err = 0; 579104476Ssam } else 580104476Ssam err = ENOMEM; 581104476Ssam return err; 582104476Ssam} 583104476Ssam 584104476Ssamstatic void 585104476Ssamcast5_zerokey(u_int8_t **sched) 586104476Ssam{ 587104476Ssam bzero(*sched, sizeof(cast_key)); 588184205Sdes free(*sched, M_CRYPTO_DATA); 589104476Ssam *sched = NULL; 590104476Ssam} 591104476Ssam 592104476Ssamstatic void 593104476Ssamskipjack_encrypt(caddr_t key, u_int8_t *blk) 594104476Ssam{ 595104476Ssam skipjack_forwards(blk, blk, (u_int8_t **) key); 596104476Ssam} 597104476Ssam 598104476Ssamstatic void 599104476Ssamskipjack_decrypt(caddr_t key, u_int8_t *blk) 600104476Ssam{ 601104476Ssam skipjack_backwards(blk, blk, (u_int8_t **) key); 602104476Ssam} 603104476Ssam 604104476Ssamstatic int 605104476Ssamskipjack_setkey(u_int8_t **sched, u_int8_t *key, int len) 606104476Ssam{ 607104476Ssam int err; 608104476Ssam 609104476Ssam /* NB: allocate all the memory that's needed at once */ 610184205Sdes *sched = malloc(10 * (sizeof(u_int8_t *) + 0x100), 611104476Ssam M_CRYPTO_DATA, M_NOWAIT|M_ZERO); 612104476Ssam if (*sched != NULL) { 613104476Ssam u_int8_t** key_tables = (u_int8_t**) *sched; 614104476Ssam u_int8_t* table = (u_int8_t*) &key_tables[10]; 615104476Ssam int k; 616104476Ssam 617104476Ssam for (k = 0; k < 10; k++) { 618104476Ssam key_tables[k] = table; 619104476Ssam table += 0x100; 620104476Ssam } 621104476Ssam subkey_table_gen(key, (u_int8_t **) *sched); 622104476Ssam err = 0; 623104476Ssam } else 624104476Ssam err = ENOMEM; 625104476Ssam return err; 626104476Ssam} 627104476Ssam 628104476Ssamstatic void 629104476Ssamskipjack_zerokey(u_int8_t **sched) 630104476Ssam{ 631104476Ssam bzero(*sched, 10 * (sizeof(u_int8_t *) + 0x100)); 632184205Sdes free(*sched, M_CRYPTO_DATA); 633104476Ssam *sched = NULL; 634104476Ssam} 635104476Ssam 636104476Ssamstatic void 637104476Ssamrijndael128_encrypt(caddr_t key, u_int8_t *blk) 638104476Ssam{ 639104476Ssam rijndael_encrypt((rijndael_ctx *) key, (u_char *) blk, (u_char *) blk); 640104476Ssam} 641104476Ssam 642104476Ssamstatic void 643104476Ssamrijndael128_decrypt(caddr_t key, u_int8_t *blk) 644104476Ssam{ 645143408Sume rijndael_decrypt(((rijndael_ctx *) key), (u_char *) blk, 646104476Ssam (u_char *) blk); 647104476Ssam} 648104476Ssam 649104476Ssamstatic int 650104476Ssamrijndael128_setkey(u_int8_t **sched, u_int8_t *key, int len) 651104476Ssam{ 652104476Ssam int err; 653104476Ssam 654149143Spjd if (len != 16 && len != 24 && len != 32) 655149143Spjd return (EINVAL); 656184205Sdes *sched = malloc(sizeof(rijndael_ctx), M_CRYPTO_DATA, 657104476Ssam M_NOWAIT|M_ZERO); 658104476Ssam if (*sched != NULL) { 659143408Sume rijndael_set_key((rijndael_ctx *) *sched, (u_char *) key, 660143408Sume len * 8); 661104476Ssam err = 0; 662104476Ssam } else 663104476Ssam err = ENOMEM; 664104476Ssam return err; 665104476Ssam} 666104476Ssam 667104476Ssamstatic void 668104476Ssamrijndael128_zerokey(u_int8_t **sched) 669104476Ssam{ 670143408Sume bzero(*sched, sizeof(rijndael_ctx)); 671184205Sdes free(*sched, M_CRYPTO_DATA); 672104476Ssam *sched = NULL; 673104476Ssam} 674104476Ssam 675275732Sjmgvoid 676275732Sjmgaes_icm_reinit(caddr_t key, u_int8_t *iv) 677275732Sjmg{ 678275732Sjmg struct aes_icm_ctx *ctx; 679275732Sjmg 680275732Sjmg ctx = (struct aes_icm_ctx *)key; 681275732Sjmg bcopy(iv, ctx->ac_block, AESICM_BLOCKSIZE); 682275732Sjmg} 683275732Sjmg 684275732Sjmgvoid 685275732Sjmgaes_gcm_reinit(caddr_t key, u_int8_t *iv) 686275732Sjmg{ 687275732Sjmg struct aes_icm_ctx *ctx; 688275732Sjmg 689275732Sjmg aes_icm_reinit(key, iv); 690275732Sjmg 691275732Sjmg ctx = (struct aes_icm_ctx *)key; 692275732Sjmg /* GCM starts with 2 as counter 1 is used for final xor of tag. */ 693275732Sjmg bzero(&ctx->ac_block[AESICM_BLOCKSIZE - 4], 4); 694275732Sjmg ctx->ac_block[AESICM_BLOCKSIZE - 1] = 2; 695275732Sjmg} 696275732Sjmg 697275732Sjmgvoid 698275732Sjmgaes_icm_crypt(caddr_t key, u_int8_t *data) 699275732Sjmg{ 700275732Sjmg struct aes_icm_ctx *ctx; 701275732Sjmg u_int8_t keystream[AESICM_BLOCKSIZE]; 702275732Sjmg int i; 703275732Sjmg 704275732Sjmg ctx = (struct aes_icm_ctx *)key; 705275732Sjmg rijndaelEncrypt(ctx->ac_ek, ctx->ac_nr, ctx->ac_block, keystream); 706275732Sjmg for (i = 0; i < AESICM_BLOCKSIZE; i++) 707275732Sjmg data[i] ^= keystream[i]; 708275732Sjmg explicit_bzero(keystream, sizeof(keystream)); 709275732Sjmg 710275732Sjmg /* increment counter */ 711275732Sjmg for (i = AESICM_BLOCKSIZE - 1; 712275732Sjmg i >= 0; i--) 713275732Sjmg if (++ctx->ac_block[i]) /* continue on overflow */ 714275732Sjmg break; 715275732Sjmg} 716275732Sjmg 717275732Sjmgint 718275732Sjmgaes_icm_setkey(u_int8_t **sched, u_int8_t *key, int len) 719275732Sjmg{ 720275732Sjmg struct aes_icm_ctx *ctx; 721275732Sjmg 722275732Sjmg *sched = malloc(sizeof(struct aes_icm_ctx), M_CRYPTO_DATA, 723275732Sjmg M_NOWAIT | M_ZERO); 724275732Sjmg if (*sched == NULL) 725275732Sjmg return ENOMEM; 726275732Sjmg 727275732Sjmg ctx = (struct aes_icm_ctx *)*sched; 728275732Sjmg ctx->ac_nr = rijndaelKeySetupEnc(ctx->ac_ek, (u_char *)key, len * 8); 729275732Sjmg if (ctx->ac_nr == 0) 730275732Sjmg return EINVAL; 731275732Sjmg return 0; 732275732Sjmg} 733275732Sjmg 734275732Sjmgvoid 735275732Sjmgaes_icm_zerokey(u_int8_t **sched) 736275732Sjmg{ 737275732Sjmg 738275732Sjmg bzero(*sched, sizeof(struct aes_icm_ctx)); 739275732Sjmg free(*sched, M_CRYPTO_DATA); 740275732Sjmg *sched = NULL; 741275732Sjmg} 742275732Sjmg 743213068Spjd#define AES_XTS_BLOCKSIZE 16 744213068Spjd#define AES_XTS_IVSIZE 8 745213068Spjd#define AES_XTS_ALPHA 0x87 /* GF(2^128) generator polynomial */ 746213068Spjd 747213068Spjdstruct aes_xts_ctx { 748213068Spjd rijndael_ctx key1; 749213068Spjd rijndael_ctx key2; 750213068Spjd u_int8_t tweak[AES_XTS_BLOCKSIZE]; 751213068Spjd}; 752213068Spjd 753213068Spjdvoid 754213068Spjdaes_xts_reinit(caddr_t key, u_int8_t *iv) 755213068Spjd{ 756213068Spjd struct aes_xts_ctx *ctx = (struct aes_xts_ctx *)key; 757213068Spjd u_int64_t blocknum; 758213068Spjd u_int i; 759213068Spjd 760213068Spjd /* 761213068Spjd * Prepare tweak as E_k2(IV). IV is specified as LE representation 762213068Spjd * of a 64-bit block number which we allow to be passed in directly. 763213068Spjd */ 764213068Spjd bcopy(iv, &blocknum, AES_XTS_IVSIZE); 765213068Spjd for (i = 0; i < AES_XTS_IVSIZE; i++) { 766213068Spjd ctx->tweak[i] = blocknum & 0xff; 767213068Spjd blocknum >>= 8; 768213068Spjd } 769213068Spjd /* Last 64 bits of IV are always zero */ 770213068Spjd bzero(ctx->tweak + AES_XTS_IVSIZE, AES_XTS_IVSIZE); 771213068Spjd 772213068Spjd rijndael_encrypt(&ctx->key2, ctx->tweak, ctx->tweak); 773213068Spjd} 774213068Spjd 775169425Sgnnstatic void 776213068Spjdaes_xts_crypt(struct aes_xts_ctx *ctx, u_int8_t *data, u_int do_encrypt) 777213068Spjd{ 778213068Spjd u_int8_t block[AES_XTS_BLOCKSIZE]; 779213068Spjd u_int i, carry_in, carry_out; 780213068Spjd 781213068Spjd for (i = 0; i < AES_XTS_BLOCKSIZE; i++) 782213068Spjd block[i] = data[i] ^ ctx->tweak[i]; 783213068Spjd 784213068Spjd if (do_encrypt) 785213068Spjd rijndael_encrypt(&ctx->key1, block, data); 786213068Spjd else 787213068Spjd rijndael_decrypt(&ctx->key1, block, data); 788213068Spjd 789213068Spjd for (i = 0; i < AES_XTS_BLOCKSIZE; i++) 790213068Spjd data[i] ^= ctx->tweak[i]; 791213068Spjd 792213068Spjd /* Exponentiate tweak */ 793213068Spjd carry_in = 0; 794213068Spjd for (i = 0; i < AES_XTS_BLOCKSIZE; i++) { 795213068Spjd carry_out = ctx->tweak[i] & 0x80; 796213068Spjd ctx->tweak[i] = (ctx->tweak[i] << 1) | (carry_in ? 1 : 0); 797213068Spjd carry_in = carry_out; 798213068Spjd } 799213068Spjd if (carry_in) 800213068Spjd ctx->tweak[0] ^= AES_XTS_ALPHA; 801213068Spjd bzero(block, sizeof(block)); 802213068Spjd} 803213068Spjd 804213068Spjdvoid 805213068Spjdaes_xts_encrypt(caddr_t key, u_int8_t *data) 806213068Spjd{ 807213068Spjd aes_xts_crypt((struct aes_xts_ctx *)key, data, 1); 808213068Spjd} 809213068Spjd 810213068Spjdvoid 811213068Spjdaes_xts_decrypt(caddr_t key, u_int8_t *data) 812213068Spjd{ 813213068Spjd aes_xts_crypt((struct aes_xts_ctx *)key, data, 0); 814213068Spjd} 815213068Spjd 816213068Spjdint 817213068Spjdaes_xts_setkey(u_int8_t **sched, u_int8_t *key, int len) 818213068Spjd{ 819213068Spjd struct aes_xts_ctx *ctx; 820213068Spjd 821213068Spjd if (len != 32 && len != 64) 822213068Spjd return EINVAL; 823213068Spjd 824213068Spjd *sched = malloc(sizeof(struct aes_xts_ctx), M_CRYPTO_DATA, 825213068Spjd M_NOWAIT | M_ZERO); 826213068Spjd if (*sched == NULL) 827213068Spjd return ENOMEM; 828213068Spjd ctx = (struct aes_xts_ctx *)*sched; 829213068Spjd 830213068Spjd rijndael_set_key(&ctx->key1, key, len * 4); 831213068Spjd rijndael_set_key(&ctx->key2, key + (len / 2), len * 4); 832213068Spjd 833213068Spjd return 0; 834213068Spjd} 835213068Spjd 836213068Spjdvoid 837213068Spjdaes_xts_zerokey(u_int8_t **sched) 838213068Spjd{ 839213068Spjd bzero(*sched, sizeof(struct aes_xts_ctx)); 840213068Spjd free(*sched, M_CRYPTO_DATA); 841213068Spjd *sched = NULL; 842213068Spjd} 843213068Spjd 844213068Spjdstatic void 845169425Sgnncml_encrypt(caddr_t key, u_int8_t *blk) 846169425Sgnn{ 847169425Sgnn camellia_encrypt((camellia_ctx *) key, (u_char *) blk, (u_char *) blk); 848169425Sgnn} 849169425Sgnn 850169425Sgnnstatic void 851169425Sgnncml_decrypt(caddr_t key, u_int8_t *blk) 852169425Sgnn{ 853169425Sgnn camellia_decrypt(((camellia_ctx *) key), (u_char *) blk, 854169425Sgnn (u_char *) blk); 855169425Sgnn} 856169425Sgnn 857169425Sgnnstatic int 858169425Sgnncml_setkey(u_int8_t **sched, u_int8_t *key, int len) 859169425Sgnn{ 860169425Sgnn int err; 861169425Sgnn 862169425Sgnn if (len != 16 && len != 24 && len != 32) 863169425Sgnn return (EINVAL); 864184205Sdes *sched = malloc(sizeof(camellia_ctx), M_CRYPTO_DATA, 865169425Sgnn M_NOWAIT|M_ZERO); 866169425Sgnn if (*sched != NULL) { 867169425Sgnn camellia_set_key((camellia_ctx *) *sched, (u_char *) key, 868169425Sgnn len * 8); 869169425Sgnn err = 0; 870169425Sgnn } else 871169425Sgnn err = ENOMEM; 872169425Sgnn return err; 873169425Sgnn} 874169425Sgnn 875169425Sgnnstatic void 876169425Sgnncml_zerokey(u_int8_t **sched) 877169425Sgnn{ 878169425Sgnn bzero(*sched, sizeof(camellia_ctx)); 879184205Sdes free(*sched, M_CRYPTO_DATA); 880169425Sgnn *sched = NULL; 881169425Sgnn} 882169425Sgnn 883104476Ssam/* 884104476Ssam * And now for auth. 885104476Ssam */ 886104476Ssam 887104476Ssamstatic void 888104476Ssamnull_init(void *ctx) 889104476Ssam{ 890104476Ssam} 891104476Ssam 892275732Sjmgstatic void 893275732Sjmgnull_reinit(void *ctx, const u_int8_t *buf, u_int16_t len) 894275732Sjmg{ 895275732Sjmg} 896275732Sjmg 897104476Ssamstatic int 898275732Sjmgnull_update(void *ctx, const u_int8_t *buf, u_int16_t len) 899104476Ssam{ 900104476Ssam return 0; 901104476Ssam} 902104476Ssam 903104476Ssamstatic void 904104476Ssamnull_final(u_int8_t *buf, void *ctx) 905104476Ssam{ 906104476Ssam if (buf != (u_int8_t *) 0) 907104476Ssam bzero(buf, 12); 908104476Ssam} 909104476Ssam 910104476Ssamstatic int 911275732SjmgRMD160Update_int(void *ctx, const u_int8_t *buf, u_int16_t len) 912104476Ssam{ 913104476Ssam RMD160Update(ctx, buf, len); 914104476Ssam return 0; 915104476Ssam} 916104476Ssam 917104476Ssamstatic int 918275732SjmgMD5Update_int(void *ctx, const u_int8_t *buf, u_int16_t len) 919104476Ssam{ 920104476Ssam MD5Update(ctx, buf, len); 921104476Ssam return 0; 922104476Ssam} 923104476Ssam 924104476Ssamstatic void 925104476SsamSHA1Init_int(void *ctx) 926104476Ssam{ 927104476Ssam SHA1Init(ctx); 928104476Ssam} 929104476Ssam 930104476Ssamstatic int 931275732SjmgSHA1Update_int(void *ctx, const u_int8_t *buf, u_int16_t len) 932104476Ssam{ 933104476Ssam SHA1Update(ctx, buf, len); 934104476Ssam return 0; 935104476Ssam} 936104476Ssam 937104476Ssamstatic void 938104476SsamSHA1Final_int(u_int8_t *blk, void *ctx) 939104476Ssam{ 940104476Ssam SHA1Final(blk, ctx); 941104476Ssam} 942104476Ssam 943104476Ssamstatic int 944275732SjmgSHA256Update_int(void *ctx, const u_int8_t *buf, u_int16_t len) 945104476Ssam{ 946104476Ssam SHA256_Update(ctx, buf, len); 947104476Ssam return 0; 948104476Ssam} 949104476Ssam 950104476Ssamstatic int 951275732SjmgSHA384Update_int(void *ctx, const u_int8_t *buf, u_int16_t len) 952104476Ssam{ 953104476Ssam SHA384_Update(ctx, buf, len); 954104476Ssam return 0; 955104476Ssam} 956104476Ssam 957104476Ssamstatic int 958275732SjmgSHA512Update_int(void *ctx, const u_int8_t *buf, u_int16_t len) 959104476Ssam{ 960104476Ssam SHA512_Update(ctx, buf, len); 961104476Ssam return 0; 962104476Ssam} 963104476Ssam 964104476Ssam/* 965104476Ssam * And compression 966104476Ssam */ 967104476Ssam 968104476Ssamstatic u_int32_t 969104476Ssamdeflate_compress(data, size, out) 970104476Ssam u_int8_t *data; 971104476Ssam u_int32_t size; 972104476Ssam u_int8_t **out; 973104476Ssam{ 974104476Ssam return deflate_global(data, size, 0, out); 975104476Ssam} 976104476Ssam 977104476Ssamstatic u_int32_t 978104476Ssamdeflate_decompress(data, size, out) 979104476Ssam u_int8_t *data; 980104476Ssam u_int32_t size; 981104476Ssam u_int8_t **out; 982104476Ssam{ 983104476Ssam return deflate_global(data, size, 1, out); 984104476Ssam} 985