11.2Sriastrad/*	$NetBSD: aes_keysched.c,v 1.2 2025/11/23 22:44:14 riastradh Exp $	*/
21.1Sriastrad
31.1Sriastrad/*-
41.1Sriastrad * Copyright (c) 2025 The NetBSD Foundation, Inc.
51.1Sriastrad * All rights reserved.
61.1Sriastrad *
71.1Sriastrad * Redistribution and use in source and binary forms, with or without
81.1Sriastrad * modification, are permitted provided that the following conditions
91.1Sriastrad * are met:
101.1Sriastrad * 1. Redistributions of source code must retain the above copyright
111.1Sriastrad *    notice, this list of conditions and the following disclaimer.
121.1Sriastrad * 2. Redistributions in binary form must reproduce the above copyright
131.1Sriastrad *    notice, this list of conditions and the following disclaimer in the
141.1Sriastrad *    documentation and/or other materials provided with the distribution.
151.1Sriastrad *
161.1Sriastrad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
171.1Sriastrad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
181.1Sriastrad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
191.1Sriastrad * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
201.1Sriastrad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
211.1Sriastrad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
221.1Sriastrad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
231.1Sriastrad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
241.1Sriastrad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
251.1Sriastrad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
261.1Sriastrad * POSSIBILITY OF SUCH DAMAGE.
271.1Sriastrad */
281.1Sriastrad
291.1Sriastrad#include <sys/cdefs.h>
301.2Sriastrad__KERNEL_RCSID(1, "$NetBSD: aes_keysched.c,v 1.2 2025/11/23 22:44:14 riastradh Exp $");
311.2Sriastrad
321.2Sriastrad#ifdef _KERNEL_OPT
331.2Sriastrad#include "opt_aes.h"
341.2Sriastrad#endif
351.1Sriastrad
361.1Sriastrad#include <sys/types.h>
371.1Sriastrad
381.2Sriastrad#include <crypto/aes/aes_keysched.h>
391.2Sriastrad
401.2Sriastrad#ifdef AES_BEAR64
411.2Sriastrad#include <crypto/aes/aes_bear64.h>
421.2Sriastrad#else
431.1Sriastrad#include <crypto/aes/aes_bear.h>
441.2Sriastrad#endif
451.1Sriastrad
461.1Sriastrad/*
471.1Sriastrad * aes_keysched_enc(rk, key, keybytes)
481.1Sriastrad *
491.1Sriastrad *	Compute the standard AES encryption key schedule, expanding a
501.1Sriastrad *	16-, 24-, or 32-byte key into 44, 52, or 60 32-bit round keys
511.1Sriastrad *	for encryption.  Returns the number of rounds for the key of
521.1Sriastrad *	this length.
531.1Sriastrad */
541.1Sriastradu_int
551.1Sriastradaes_keysched_enc(uint32_t *rk, const void *key, size_t keybytes)
561.1Sriastrad{
571.1Sriastrad
581.2Sriastrad#ifdef AES_BEAR64
591.2Sriastrad	return br_aes_ct64_keysched_stdenc(rk, key, keybytes);
601.2Sriastrad#else
611.1Sriastrad	return br_aes_ct_keysched_stdenc(rk, key, keybytes);
621.2Sriastrad#endif
631.1Sriastrad}
641.1Sriastrad
651.1Sriastrad/*
661.1Sriastrad * aes_keysched_dec(rk, key, keybytes)
671.1Sriastrad *
681.1Sriastrad *	Compute the standard AES decryption key schedule, expanding a
691.1Sriastrad *	16-, 24-, or 32-byte key into 44, 52, or 60 32-bit round keys
701.1Sriastrad *	and applying InvMixColumns for decryption.  Returns the number
711.1Sriastrad *	of rounds for the key of this length.
721.1Sriastrad */
731.1Sriastradu_int
741.1Sriastradaes_keysched_dec(uint32_t *rk, const void *key, size_t keybytes)
751.1Sriastrad{
761.1Sriastrad
771.2Sriastrad#ifdef AES_BEAR64
781.2Sriastrad	return br_aes_ct64_keysched_stddec(rk, key, keybytes);
791.2Sriastrad#else
801.1Sriastrad	return br_aes_ct_keysched_stddec(rk, key, keybytes);
811.2Sriastrad#endif
821.1Sriastrad}
83