/* $OpenBSD: xform.c,v 1.16 2001/08/28 12:20:43 ben Exp $ */1/*-2* The authors of this code are John Ioannidis ([email protected]),3* Angelos D. Keromytis ([email protected]),4* Niels Provos ([email protected]) and5* Damien Miller ([email protected]).6*7* This code was written by John Ioannidis for BSD/OS in Athens, Greece,8* in November 1995.9*10* Ported to OpenBSD and NetBSD, with additional transforms, in December 1996,11* by Angelos D. Keromytis.12*13* Additional transforms and features in 1997 and 1998 by Angelos D. Keromytis14* and Niels Provos.15*16* Additional features in 1999 by Angelos D. Keromytis.17*18* AES XTS implementation in 2008 by Damien Miller19*20* Copyright (C) 1995, 1996, 1997, 1998, 1999 by John Ioannidis,21* Angelos D. Keromytis and Niels Provos.22*23* Copyright (C) 2001, Angelos D. Keromytis.24*25* Copyright (C) 2008, Damien Miller26* Copyright (c) 2014 The FreeBSD Foundation27* All rights reserved.28*29* Portions of this software were developed by John-Mark Gurney30* under sponsorship of the FreeBSD Foundation and31* Rubicon Communications, LLC (Netgate).32*33* Permission to use, copy, and modify this software with or without fee34* is hereby granted, provided that this entire notice is included in35* all copies of any software which is or includes a copy or36* modification of this software.37* You may use this code under the GNU public license if you so wish. Please38* contribute changes back to the authors under this freer than GPL license39* so that we may further the use of strong encryption without limitations to40* all.41*42* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR43* IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY44* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE45* MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR46* PURPOSE.47*/4849#include <sys/cdefs.h>50#include <opencrypto/xform_auth.h>51#include <opencrypto/xform_enc.h>5253static int null_setkey(void *, const uint8_t *, int);54static void null_crypt(void *, const uint8_t *, uint8_t *);55static void null_crypt_multi(void *, const uint8_t *, uint8_t *, size_t);5657static void null_init(void *);58static void null_reinit(void *ctx, const uint8_t *buf, u_int len);59static int null_update(void *, const void *, u_int);60static void null_final(uint8_t *, void *);6162/* Encryption instances */63const struct enc_xform enc_xform_null = {64.type = CRYPTO_NULL_CBC,65.name = "NULL",66/* NB: blocksize of 4 is to generate a properly aligned ESP header */67.blocksize = NULL_BLOCK_LEN,68.ivsize = 0,69.minkey = NULL_MIN_KEY,70.maxkey = NULL_MAX_KEY,71.setkey = null_setkey,72.encrypt = null_crypt,73.decrypt = null_crypt,74.encrypt_multi = null_crypt_multi,75.decrypt_multi = null_crypt_multi,76};7778/* Authentication instances */79const struct auth_hash auth_hash_null = {80.type = CRYPTO_NULL_HMAC,81.name = "NULL-HMAC",82.keysize = 0,83.hashsize = NULL_HASH_LEN,84.ctxsize = sizeof(int), /* NB: context isn't used */85.blocksize = NULL_HMAC_BLOCK_LEN,86.Init = null_init,87.Setkey = null_reinit,88.Reinit = null_reinit,89.Update = null_update,90.Final = null_final,91};9293/*94* Encryption wrapper routines.95*/96static void97null_crypt(void *key, const uint8_t *in, uint8_t *out)98{99if (in != out)100memcpy(out, in, NULL_BLOCK_LEN);101}102103static void104null_crypt_multi(void *key, const uint8_t *in, uint8_t *out, size_t len)105{106if (in != out)107memcpy(out, in, len);108}109110static int111null_setkey(void *sched, const uint8_t *key, int len)112{113return (0);114}115116/*117* And now for auth.118*/119120static void121null_init(void *ctx)122{123}124125static void126null_reinit(void *ctx, const uint8_t *buf, u_int len)127{128}129130static int131null_update(void *ctx, const void *buf, u_int len)132{133return (0);134}135136static void137null_final(uint8_t *buf, void *ctx)138{139bzero(buf, NULL_HASH_LEN);140}141142143