198524Sfenner/*	$OpenBSD: xform.h,v 1.32 2021/10/22 12:30:53 bluhm Exp $	*/
298524Sfenner
398524Sfenner/*
498524Sfenner * The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu)
598524Sfenner *
698524Sfenner * This code was written by Angelos D. Keromytis in Athens, Greece, in
798524Sfenner * February 2000. Network Security Technologies Inc. (NSTI) kindly
898524Sfenner * supported the development of this code.
998524Sfenner *
1098524Sfenner * Copyright (c) 2000 Angelos D. Keromytis
1198524Sfenner *
1298524Sfenner * Permission to use, copy, and modify this software with or without fee
1398524Sfenner * is hereby granted, provided that this entire notice is included in
1498524Sfenner * all source code copies of any software which is or includes a copy or
1598524Sfenner * modification of this software.
1698524Sfenner *
1798524Sfenner * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
1898524Sfenner * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
1998524Sfenner * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
2098524Sfenner * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
2198524Sfenner * PURPOSE.
2298524Sfenner */
2398524Sfenner
24127668Sbms#ifndef _CRYPTO_XFORM_H_
25214478Srpaulo#define _CRYPTO_XFORM_H_
2698524Sfenner
2798524Sfenner#include <crypto/md5.h>
2898524Sfenner#include <crypto/sha1.h>
2998524Sfenner#include <crypto/rmd160.h>
3098524Sfenner#include <crypto/sha2.h>
3198524Sfenner#include <crypto/gmac.h>
32127668Sbms
3398524Sfenner#define AESCTR_NONCESIZE	4
3498524Sfenner#define AESCTR_IVSIZE		8
3598524Sfenner#define AESCTR_BLOCKSIZE	16
3698524Sfenner
3798524Sfenner#define AES_XTS_BLOCKSIZE	16
3898524Sfenner#define AES_XTS_IVSIZE		8
3998524Sfenner#define AES_XTS_ALPHA		0x87	/* GF(2^128) generator polynomial */
4098524Sfenner
4198524Sfenner/* Declarations */
4298524Sfennerstruct auth_hash {
4398524Sfenner	int type;
44146773Ssam	char *name;
45146773Ssam	u_int16_t keysize;
4698524Sfenner	u_int16_t hashsize;
47146773Ssam	u_int16_t authsize;
4898524Sfenner	u_int16_t ctxsize;
49172686Smlaier	u_int16_t blocksize;
50214478Srpaulo	void (*Init) (void *);
51172686Smlaier	void (*Setkey) (void *, const u_int8_t *, u_int16_t);
52172686Smlaier	void (*Reinit) (void *, const u_int8_t *, u_int16_t);
53172686Smlaier	int  (*Update) (void *, const u_int8_t *, u_int16_t);
54172686Smlaier	void (*Final) (u_int8_t *, void *);
55172686Smlaier};
56146773Ssam
57146773Ssamstruct enc_xform {
58111726Sfenner	int type;
59214478Srpaulo	char *name;
60214478Srpaulo	u_int16_t blocksize;
61214478Srpaulo	u_int16_t ivsize;
62214478Srpaulo	u_int16_t minkey;
63214478Srpaulo	u_int16_t maxkey;
64214478Srpaulo	u_int16_t ctxsize;
65214478Srpaulo	void (*encrypt) (caddr_t, u_int8_t *);
66214478Srpaulo	void (*decrypt) (caddr_t, u_int8_t *);
67214478Srpaulo	int  (*setkey) (void *, u_int8_t *, int len);
68214478Srpaulo	void (*reinit) (caddr_t, u_int8_t *);
69172686Smlaier};
70172686Smlaier
71172686Smlaierstruct comp_algo {
72214478Srpaulo	int type;
73172686Smlaier	char *name;
74172686Smlaier	size_t minlen;
75172686Smlaier	u_int32_t (*compress) (u_int8_t *, u_int32_t, u_int8_t **);
7698524Sfenner	u_int32_t (*decompress) (u_int8_t *, u_int32_t, u_int8_t **);
77170533Ssam};
78170533Ssam
79170533Ssamunion authctx {
80170533Ssam	MD5_CTX md5ctx;
81170533Ssam	SHA1_CTX sha1ctx;
82170533Ssam	RMD160_CTX rmd160ctx;
83170533Ssam	SHA2_CTX sha2_ctx;
84170533Ssam	AES_GMAC_CTX aes_gmac_ctx;
85170533Ssam};
86170533Ssam
87170533Ssamextern const struct enc_xform enc_xform_3des;
88170533Ssamextern const struct enc_xform enc_xform_blf;
89170533Ssamextern const struct enc_xform enc_xform_cast5;
90170533Ssamextern const struct enc_xform enc_xform_aes;
91170533Ssamextern const struct enc_xform enc_xform_aes_ctr;
92170533Ssamextern const struct enc_xform enc_xform_aes_gcm;
93170533Ssamextern const struct enc_xform enc_xform_aes_gmac;
94170533Ssamextern const struct enc_xform enc_xform_aes_xts;
95170533Ssamextern const struct enc_xform enc_xform_chacha20_poly1305;
96170533Ssamextern const struct enc_xform enc_xform_null;
97170533Ssam
9898524Sfennerextern const struct auth_hash auth_hash_hmac_md5_96;
99162017Ssamextern const struct auth_hash auth_hash_hmac_sha1_96;
10098524Sfennerextern const struct auth_hash auth_hash_hmac_ripemd_160_96;
10198524Sfennerextern const struct auth_hash auth_hash_hmac_sha2_256_128;
102195684Ssamextern const struct auth_hash auth_hash_hmac_sha2_384_192;
103195684Ssamextern const struct auth_hash auth_hash_hmac_sha2_512_256;
104195684Ssamextern const struct auth_hash auth_hash_gmac_aes_128;
105195684Ssamextern const struct auth_hash auth_hash_gmac_aes_192;
106195684Ssamextern const struct auth_hash auth_hash_gmac_aes_256;
107195684Ssamextern const struct auth_hash auth_hash_chacha20_poly1305;
108195684Ssam
109195684Ssamextern const struct comp_algo comp_algo_deflate;
110195684Ssam
111195684Ssam#endif /* _CRYPTO_XFORM_H_ */
112195684Ssam