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$");
52116191Sobrien
53292963Sallanjude#include <crypto/sha2/sha256.h>
54292963Sallanjude#include <crypto/sha2/sha384.h>
55292963Sallanjude#include <crypto/sha2/sha512.h>
56292963Sallanjude#include <opencrypto/xform_auth.h>
57104476Ssam
58275732Sjmgstatic	int SHA256Update_int(void *, const u_int8_t *, u_int16_t);
59275732Sjmgstatic	int SHA384Update_int(void *, const u_int8_t *, u_int16_t);
60275732Sjmgstatic	int SHA512Update_int(void *, const u_int8_t *, u_int16_t);
61104476Ssam
62104476Ssam/* Authentication instances */
63104476Ssamstruct auth_hash auth_hash_hmac_sha2_256 = {
64158703Spjd	CRYPTO_SHA2_256_HMAC, "HMAC-SHA2-256",
65285336Sgnn	SHA2_256_HMAC_KEY_LEN, SHA2_256_HASH_LEN, sizeof(SHA256_CTX),
66285336Sgnn	SHA2_256_HMAC_BLOCK_LEN,
67275732Sjmg	(void (*)(void *)) SHA256_Init, NULL, NULL, SHA256Update_int,
68104476Ssam	(void (*)(u_int8_t *, void *)) SHA256_Final
69104476Ssam};
70104476Ssam
71104476Ssamstruct auth_hash auth_hash_hmac_sha2_384 = {
72158703Spjd	CRYPTO_SHA2_384_HMAC, "HMAC-SHA2-384",
73285336Sgnn	SHA2_384_HMAC_KEY_LEN, SHA2_384_HASH_LEN, sizeof(SHA384_CTX),
74285336Sgnn	SHA2_384_HMAC_BLOCK_LEN,
75275732Sjmg	(void (*)(void *)) SHA384_Init, NULL, NULL, SHA384Update_int,
76104476Ssam	(void (*)(u_int8_t *, void *)) SHA384_Final
77104476Ssam};
78104476Ssam
79104476Ssamstruct auth_hash auth_hash_hmac_sha2_512 = {
80158703Spjd	CRYPTO_SHA2_512_HMAC, "HMAC-SHA2-512",
81285336Sgnn	SHA2_512_HMAC_KEY_LEN, SHA2_512_HASH_LEN, sizeof(SHA512_CTX),
82285336Sgnn	SHA2_512_HMAC_BLOCK_LEN,
83275732Sjmg	(void (*)(void *)) SHA512_Init, NULL, NULL, SHA512Update_int,
84104476Ssam	(void (*)(u_int8_t *, void *)) SHA512_Final
85104476Ssam};
86104476Ssam
87104476Ssam/*
88104476Ssam * And now for auth.
89104476Ssam */
90104476Ssamstatic int
91275732SjmgSHA256Update_int(void *ctx, const u_int8_t *buf, u_int16_t len)
92104476Ssam{
93104476Ssam	SHA256_Update(ctx, buf, len);
94104476Ssam	return 0;
95104476Ssam}
96104476Ssam
97104476Ssamstatic int
98275732SjmgSHA384Update_int(void *ctx, const u_int8_t *buf, u_int16_t len)
99104476Ssam{
100104476Ssam	SHA384_Update(ctx, buf, len);
101104476Ssam	return 0;
102104476Ssam}
103104476Ssam
104104476Ssamstatic int
105275732SjmgSHA512Update_int(void *ctx, const u_int8_t *buf, u_int16_t len)
106104476Ssam{
107104476Ssam	SHA512_Update(ctx, buf, len);
108104476Ssam	return 0;
109104476Ssam}
110