blob: 3d4e285bb17a80876d7c894ba48a31ca4e90b67c [file] [log] [blame]
djm@openbsd.orgd081f012020-03-13 03:17:07 +00001/* $OpenBSD: umac.c,v 1.20 2020/03/13 03:17:07 djm Exp $ */
Damien Millere45796f2007-06-11 14:01:42 +10002/* -----------------------------------------------------------------------
djm@openbsd.org@openbsd.org7f257bf2017-11-28 06:04:51 +00003 *
Damien Millere45796f2007-06-11 14:01:42 +10004 * umac.c -- C Implementation UMAC Message Authentication
5 *
6 * Version 0.93b of rfc4418.txt -- 2006 July 18
7 *
8 * For a full description of UMAC message authentication see the UMAC
9 * world-wide-web page at http://www.cs.ucdavis.edu/~rogaway/umac
10 * Please report bugs and suggestions to the UMAC webpage.
11 *
12 * Copyright (c) 1999-2006 Ted Krovetz
djm@openbsd.org@openbsd.org7f257bf2017-11-28 06:04:51 +000013 *
Damien Millere45796f2007-06-11 14:01:42 +100014 * Permission to use, copy, modify, and distribute this software and
15 * its documentation for any purpose and with or without fee, is hereby
16 * granted provided that the above copyright notice appears in all copies
17 * and in supporting documentation, and that the name of the copyright
18 * holder not be used in advertising or publicity pertaining to
19 * distribution of the software without specific, written prior permission.
20 *
djm@openbsd.org@openbsd.org7f257bf2017-11-28 06:04:51 +000021 * Comments should be directed to Ted Krovetz (tdk@acm.org)
22 *
Damien Millere45796f2007-06-11 14:01:42 +100023 * ---------------------------------------------------------------------- */
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +000024
Damien Millere45796f2007-06-11 14:01:42 +100025 /* ////////////////////// IMPORTANT NOTES /////////////////////////////////
26 *
27 * 1) This version does not work properly on messages larger than 16MB
28 *
29 * 2) If you set the switch to use SSE2, then all data must be 16-byte
30 * aligned
31 *
32 * 3) When calling the function umac(), it is assumed that msg is in
33 * a writable buffer of length divisible by 32 bytes. The message itself
34 * does not have to fill the entire buffer, but bytes beyond msg may be
35 * zeroed.
36 *
37 * 4) Three free AES implementations are supported by this implementation of
38 * UMAC. Paulo Barreto's version is in the public domain and can be found
39 * at http://www.esat.kuleuven.ac.be/~rijmen/rijndael/ (search for
40 * "Barreto"). The only two files needed are rijndael-alg-fst.c and
41 * rijndael-alg-fst.h. Brian Gladman's version is distributed with the GNU
djm@openbsd.orgd081f012020-03-13 03:17:07 +000042 * Public license at http://fp.gladman.plus.com/AES/index.htm. It
Damien Millere45796f2007-06-11 14:01:42 +100043 * includes a fast IA-32 assembly version. The OpenSSL crypo library is
44 * the third.
45 *
46 * 5) With FORCE_C_ONLY flags set to 0, incorrect results are sometimes
47 * produced under gcc with optimizations set -O3 or higher. Dunno why.
48 *
49 /////////////////////////////////////////////////////////////////////// */
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +000050
Damien Millere45796f2007-06-11 14:01:42 +100051/* ---------------------------------------------------------------------- */
52/* --- User Switches ---------------------------------------------------- */
53/* ---------------------------------------------------------------------- */
54
Darren Tucker992faad2012-10-05 11:38:24 +100055#ifndef UMAC_OUTPUT_LEN
Damien Millere45796f2007-06-11 14:01:42 +100056#define UMAC_OUTPUT_LEN 8 /* Alowable: 4, 8, 12, 16 */
Darren Tucker992faad2012-10-05 11:38:24 +100057#endif
Darren Tucker50ce4472012-10-05 12:11:33 +100058
59#if UMAC_OUTPUT_LEN != 4 && UMAC_OUTPUT_LEN != 8 && \
60 UMAC_OUTPUT_LEN != 12 && UMAC_OUTPUT_LEN != 16
61# error UMAC_OUTPUT_LEN must be defined to 4, 8, 12 or 16
62#endif
63
Damien Millere45796f2007-06-11 14:01:42 +100064/* #define FORCE_C_ONLY 1 ANSI C and 64-bit integers req'd */
65/* #define AES_IMPLEMENTAION 1 1 = OpenSSL, 2 = Barreto, 3 = Gladman */
66/* #define SSE2 0 Is SSE2 is available? */
67/* #define RUN_TESTS 0 Run basic correctness/speed tests */
djm@openbsd.org001aa552018-04-10 00:10:49 +000068/* #define UMAC_AE_SUPPORT 0 Enable authenticated encryption */
Damien Millere45796f2007-06-11 14:01:42 +100069
70/* ---------------------------------------------------------------------- */
71/* -- Global Includes --------------------------------------------------- */
72/* ---------------------------------------------------------------------- */
73
74#include "includes.h"
75#include <sys/types.h>
Damien Miller88856692014-04-20 13:33:19 +100076#include <string.h>
Darren Tucker2b523d22019-11-13 11:56:56 +110077#include <stdarg.h>
Damien Miller88856692014-04-20 13:33:19 +100078#include <stdio.h>
79#include <stdlib.h>
80#include <stddef.h>
Damien Millere45796f2007-06-11 14:01:42 +100081
Damien Miller83e04f22007-09-17 16:11:01 +100082#include "xmalloc.h"
Damien Millere45796f2007-06-11 14:01:42 +100083#include "umac.h"
Damien Miller88856692014-04-20 13:33:19 +100084#include "misc.h"
Damien Millere45796f2007-06-11 14:01:42 +100085
86/* ---------------------------------------------------------------------- */
87/* --- Primitive Data Types --- */
88/* ---------------------------------------------------------------------- */
89
90/* The following assumptions may need change on your system */
91typedef u_int8_t UINT8; /* 1 byte */
92typedef u_int16_t UINT16; /* 2 byte */
93typedef u_int32_t UINT32; /* 4 byte */
94typedef u_int64_t UINT64; /* 8 bytes */
95typedef unsigned int UWORD; /* Register */
96
97/* ---------------------------------------------------------------------- */
98/* --- Constants -------------------------------------------------------- */
99/* ---------------------------------------------------------------------- */
100
101#define UMAC_KEY_LEN 16 /* UMAC takes 16 bytes of external key */
102
103/* Message "words" are read from memory in an endian-specific manner. */
104/* For this implementation to behave correctly, __LITTLE_ENDIAN__ must */
105/* be set true if the host computer is little-endian. */
106
107#if BYTE_ORDER == LITTLE_ENDIAN
108#define __LITTLE_ENDIAN__ 1
109#else
110#define __LITTLE_ENDIAN__ 0
111#endif
112
113/* ---------------------------------------------------------------------- */
114/* ---------------------------------------------------------------------- */
115/* ----- Architecture Specific ------------------------------------------ */
116/* ---------------------------------------------------------------------- */
117/* ---------------------------------------------------------------------- */
118
119
120/* ---------------------------------------------------------------------- */
121/* ---------------------------------------------------------------------- */
122/* ----- Primitive Routines --------------------------------------------- */
123/* ---------------------------------------------------------------------- */
124/* ---------------------------------------------------------------------- */
125
126
127/* ---------------------------------------------------------------------- */
128/* --- 32-bit by 32-bit to 64-bit Multiplication ------------------------ */
129/* ---------------------------------------------------------------------- */
130
131#define MUL64(a,b) ((UINT64)((UINT64)(UINT32)(a) * (UINT64)(UINT32)(b)))
132
133/* ---------------------------------------------------------------------- */
134/* --- Endian Conversion --- Forcing assembly on some platforms */
135/* ---------------------------------------------------------------------- */
136
Damien Millere45796f2007-06-11 14:01:42 +1000137#if (__LITTLE_ENDIAN__)
Damien Miller88856692014-04-20 13:33:19 +1000138#define LOAD_UINT32_REVERSED(p) get_u32(p)
139#define STORE_UINT32_REVERSED(p,v) put_u32(p,v)
Damien Millere45796f2007-06-11 14:01:42 +1000140#else
Damien Miller88856692014-04-20 13:33:19 +1000141#define LOAD_UINT32_REVERSED(p) get_u32_le(p)
142#define STORE_UINT32_REVERSED(p,v) put_u32_le(p,v)
Damien Millere45796f2007-06-11 14:01:42 +1000143#endif
144
Damien Miller88856692014-04-20 13:33:19 +1000145#define LOAD_UINT32_LITTLE(p) (get_u32_le(p))
146#define STORE_UINT32_BIG(p,v) put_u32(p, v)
147
Damien Millere45796f2007-06-11 14:01:42 +1000148/* ---------------------------------------------------------------------- */
149/* ---------------------------------------------------------------------- */
150/* ----- Begin KDF & PDF Section ---------------------------------------- */
151/* ---------------------------------------------------------------------- */
152/* ---------------------------------------------------------------------- */
153
154/* UMAC uses AES with 16 byte block and key lengths */
155#define AES_BLOCK_LEN 16
156
157/* OpenSSL's AES */
Damien Miller294c58a2014-05-15 14:35:03 +1000158#ifdef WITH_OPENSSL
Darren Tuckercb520172007-06-14 23:21:32 +1000159#include "openbsd-compat/openssl-compat.h"
160#ifndef USE_BUILTIN_RIJNDAEL
161# include <openssl/aes.h>
162#endif
Damien Millere45796f2007-06-11 14:01:42 +1000163typedef AES_KEY aes_int_key[1];
164#define aes_encryption(in,out,int_key) \
165 AES_encrypt((u_char *)(in),(u_char *)(out),(AES_KEY *)int_key)
166#define aes_key_setup(key,int_key) \
Damien Millerc331dbd2013-07-25 11:55:20 +1000167 AES_set_encrypt_key((const u_char *)(key),UMAC_KEY_LEN*8,int_key)
Damien Miller294c58a2014-05-15 14:35:03 +1000168#else
169#include "rijndael.h"
170#define AES_ROUNDS ((UMAC_KEY_LEN / 4) + 6)
171typedef UINT8 aes_int_key[AES_ROUNDS+1][4][4]; /* AES internal */
172#define aes_encryption(in,out,int_key) \
173 rijndaelEncrypt((u32 *)(int_key), AES_ROUNDS, (u8 *)(in), (u8 *)(out))
174#define aes_key_setup(key,int_key) \
175 rijndaelKeySetupEnc((u32 *)(int_key), (const unsigned char *)(key), \
176 UMAC_KEY_LEN*8)
177#endif
Damien Millere45796f2007-06-11 14:01:42 +1000178
179/* The user-supplied UMAC key is stretched using AES in a counter
180 * mode to supply all random bits needed by UMAC. The kdf function takes
181 * an AES internal key representation 'key' and writes a stream of
Damien Miller36d70562008-07-14 12:04:43 +1000182 * 'nbytes' bytes to the memory pointed at by 'bufp'. Each distinct
Damien Millere45796f2007-06-11 14:01:42 +1000183 * 'ndx' causes a distinct byte stream.
184 */
Damien Miller36d70562008-07-14 12:04:43 +1000185static void kdf(void *bufp, aes_int_key key, UINT8 ndx, int nbytes)
Damien Millere45796f2007-06-11 14:01:42 +1000186{
187 UINT8 in_buf[AES_BLOCK_LEN] = {0};
188 UINT8 out_buf[AES_BLOCK_LEN];
Damien Miller36d70562008-07-14 12:04:43 +1000189 UINT8 *dst_buf = (UINT8 *)bufp;
Damien Millere45796f2007-06-11 14:01:42 +1000190 int i;
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000191
Damien Millere45796f2007-06-11 14:01:42 +1000192 /* Setup the initial value */
193 in_buf[AES_BLOCK_LEN-9] = ndx;
194 in_buf[AES_BLOCK_LEN-1] = i = 1;
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000195
Damien Millere45796f2007-06-11 14:01:42 +1000196 while (nbytes >= AES_BLOCK_LEN) {
197 aes_encryption(in_buf, out_buf, key);
198 memcpy(dst_buf,out_buf,AES_BLOCK_LEN);
199 in_buf[AES_BLOCK_LEN-1] = ++i;
200 nbytes -= AES_BLOCK_LEN;
201 dst_buf += AES_BLOCK_LEN;
202 }
203 if (nbytes) {
204 aes_encryption(in_buf, out_buf, key);
205 memcpy(dst_buf,out_buf,nbytes);
206 }
markus@openbsd.org1e0cdf82017-05-31 08:09:45 +0000207 explicit_bzero(in_buf, sizeof(in_buf));
208 explicit_bzero(out_buf, sizeof(out_buf));
Damien Millere45796f2007-06-11 14:01:42 +1000209}
210
211/* The final UHASH result is XOR'd with the output of a pseudorandom
djm@openbsd.org@openbsd.org7f257bf2017-11-28 06:04:51 +0000212 * function. Here, we use AES to generate random output and
Damien Millere45796f2007-06-11 14:01:42 +1000213 * xor the appropriate bytes depending on the last bits of nonce.
214 * This scheme is optimized for sequential, increasing big-endian nonces.
215 */
216
217typedef struct {
218 UINT8 cache[AES_BLOCK_LEN]; /* Previous AES output is saved */
219 UINT8 nonce[AES_BLOCK_LEN]; /* The AES input making above cache */
220 aes_int_key prf_key; /* Expanded AES key for PDF */
221} pdf_ctx;
222
223static void pdf_init(pdf_ctx *pc, aes_int_key prf_key)
224{
225 UINT8 buf[UMAC_KEY_LEN];
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000226
Damien Millere45796f2007-06-11 14:01:42 +1000227 kdf(buf, prf_key, 0, UMAC_KEY_LEN);
228 aes_key_setup(buf, pc->prf_key);
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000229
Damien Millere45796f2007-06-11 14:01:42 +1000230 /* Initialize pdf and cache */
231 memset(pc->nonce, 0, sizeof(pc->nonce));
232 aes_encryption(pc->nonce, pc->cache, pc->prf_key);
markus@openbsd.org1e0cdf82017-05-31 08:09:45 +0000233 explicit_bzero(buf, sizeof(buf));
Damien Millere45796f2007-06-11 14:01:42 +1000234}
235
Damien Millerc331dbd2013-07-25 11:55:20 +1000236static void pdf_gen_xor(pdf_ctx *pc, const UINT8 nonce[8], UINT8 buf[8])
Damien Millere45796f2007-06-11 14:01:42 +1000237{
238 /* 'ndx' indicates that we'll be using the 0th or 1st eight bytes
239 * of the AES output. If last time around we returned the ndx-1st
240 * element, then we may have the result in the cache already.
241 */
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000242
Damien Millere45796f2007-06-11 14:01:42 +1000243#if (UMAC_OUTPUT_LEN == 4)
244#define LOW_BIT_MASK 3
245#elif (UMAC_OUTPUT_LEN == 8)
246#define LOW_BIT_MASK 1
247#elif (UMAC_OUTPUT_LEN > 8)
248#define LOW_BIT_MASK 0
249#endif
Damien Miller32ecfa02013-07-20 13:22:13 +1000250 union {
251 UINT8 tmp_nonce_lo[4];
252 UINT32 align;
253 } t;
Damien Millere45796f2007-06-11 14:01:42 +1000254#if LOW_BIT_MASK != 0
255 int ndx = nonce[7] & LOW_BIT_MASK;
256#endif
Damien Millerc331dbd2013-07-25 11:55:20 +1000257 *(UINT32 *)t.tmp_nonce_lo = ((const UINT32 *)nonce)[1];
Damien Miller32ecfa02013-07-20 13:22:13 +1000258 t.tmp_nonce_lo[3] &= ~LOW_BIT_MASK; /* zero last bit */
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000259
Damien Miller32ecfa02013-07-20 13:22:13 +1000260 if ( (((UINT32 *)t.tmp_nonce_lo)[0] != ((UINT32 *)pc->nonce)[1]) ||
Damien Millerc331dbd2013-07-25 11:55:20 +1000261 (((const UINT32 *)nonce)[0] != ((UINT32 *)pc->nonce)[0]) )
Damien Millere45796f2007-06-11 14:01:42 +1000262 {
Damien Millerc331dbd2013-07-25 11:55:20 +1000263 ((UINT32 *)pc->nonce)[0] = ((const UINT32 *)nonce)[0];
Damien Miller32ecfa02013-07-20 13:22:13 +1000264 ((UINT32 *)pc->nonce)[1] = ((UINT32 *)t.tmp_nonce_lo)[0];
Damien Millere45796f2007-06-11 14:01:42 +1000265 aes_encryption(pc->nonce, pc->cache, pc->prf_key);
266 }
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000267
Damien Millere45796f2007-06-11 14:01:42 +1000268#if (UMAC_OUTPUT_LEN == 4)
269 *((UINT32 *)buf) ^= ((UINT32 *)pc->cache)[ndx];
270#elif (UMAC_OUTPUT_LEN == 8)
271 *((UINT64 *)buf) ^= ((UINT64 *)pc->cache)[ndx];
272#elif (UMAC_OUTPUT_LEN == 12)
273 ((UINT64 *)buf)[0] ^= ((UINT64 *)pc->cache)[0];
274 ((UINT32 *)buf)[2] ^= ((UINT32 *)pc->cache)[2];
275#elif (UMAC_OUTPUT_LEN == 16)
276 ((UINT64 *)buf)[0] ^= ((UINT64 *)pc->cache)[0];
277 ((UINT64 *)buf)[1] ^= ((UINT64 *)pc->cache)[1];
278#endif
279}
280
281/* ---------------------------------------------------------------------- */
282/* ---------------------------------------------------------------------- */
283/* ----- Begin NH Hash Section ------------------------------------------ */
284/* ---------------------------------------------------------------------- */
285/* ---------------------------------------------------------------------- */
286
287/* The NH-based hash functions used in UMAC are described in the UMAC paper
djm@openbsd.org@openbsd.org7f257bf2017-11-28 06:04:51 +0000288 * and specification, both of which can be found at the UMAC website.
289 * The interface to this implementation has two
Damien Millere45796f2007-06-11 14:01:42 +1000290 * versions, one expects the entire message being hashed to be passed
291 * in a single buffer and returns the hash result immediately. The second
djm@openbsd.org@openbsd.org7f257bf2017-11-28 06:04:51 +0000292 * allows the message to be passed in a sequence of buffers. In the
293 * muliple-buffer interface, the client calls the routine nh_update() as
294 * many times as necessary. When there is no more data to be fed to the
295 * hash, the client calls nh_final() which calculates the hash output.
296 * Before beginning another hash calculation the nh_reset() routine
297 * must be called. The single-buffer routine, nh(), is equivalent to
298 * the sequence of calls nh_update() and nh_final(); however it is
djm@openbsd.org001aa552018-04-10 00:10:49 +0000299 * optimized and should be preferred whenever the multiple-buffer interface
djm@openbsd.org@openbsd.org7f257bf2017-11-28 06:04:51 +0000300 * is not necessary. When using either interface, it is the client's
djm@openbsd.org001aa552018-04-10 00:10:49 +0000301 * responsibility to pass no more than L1_KEY_LEN bytes per hash result.
djm@openbsd.org@openbsd.org7f257bf2017-11-28 06:04:51 +0000302 *
303 * The routine nh_init() initializes the nh_ctx data structure and
304 * must be called once, before any other PDF routine.
Damien Millere45796f2007-06-11 14:01:42 +1000305 */
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000306
Damien Millere45796f2007-06-11 14:01:42 +1000307 /* The "nh_aux" routines do the actual NH hashing work. They
308 * expect buffers to be multiples of L1_PAD_BOUNDARY. These routines
djm@openbsd.org@openbsd.org7f257bf2017-11-28 06:04:51 +0000309 * produce output for all STREAMS NH iterations in one call,
Damien Millere45796f2007-06-11 14:01:42 +1000310 * allowing the parallel implementation of the streams.
311 */
312
313#define STREAMS (UMAC_OUTPUT_LEN / 4) /* Number of times hash is applied */
314#define L1_KEY_LEN 1024 /* Internal key bytes */
315#define L1_KEY_SHIFT 16 /* Toeplitz key shift between streams */
316#define L1_PAD_BOUNDARY 32 /* pad message to boundary multiple */
317#define ALLOC_BOUNDARY 16 /* Keep buffers aligned to this */
318#define HASH_BUF_BYTES 64 /* nh_aux_hb buffer multiple */
319
320typedef struct {
321 UINT8 nh_key [L1_KEY_LEN + L1_KEY_SHIFT * (STREAMS - 1)]; /* NH Key */
Darren Tucker8a057952011-11-04 10:53:31 +1100322 UINT8 data [HASH_BUF_BYTES]; /* Incoming data buffer */
djm@openbsd.org001aa552018-04-10 00:10:49 +0000323 int next_data_empty; /* Bookkeeping variable for data buffer. */
324 int bytes_hashed; /* Bytes (out of L1_KEY_LEN) incorporated. */
Damien Millere45796f2007-06-11 14:01:42 +1000325 UINT64 state[STREAMS]; /* on-line state */
326} nh_ctx;
327
328
329#if (UMAC_OUTPUT_LEN == 4)
330
Damien Millerc331dbd2013-07-25 11:55:20 +1000331static void nh_aux(void *kp, const void *dp, void *hp, UINT32 dlen)
djm@openbsd.org@openbsd.org7f257bf2017-11-28 06:04:51 +0000332/* NH hashing primitive. Previous (partial) hash result is loaded and
Damien Millere45796f2007-06-11 14:01:42 +1000333* then stored via hp pointer. The length of the data pointed at by "dp",
334* "dlen", is guaranteed to be divisible by L1_PAD_BOUNDARY (32). Key
djm@openbsd.org@openbsd.org7f257bf2017-11-28 06:04:51 +0000335* is expected to be endian compensated in memory at key setup.
Damien Millere45796f2007-06-11 14:01:42 +1000336*/
337{
338 UINT64 h;
339 UWORD c = dlen / 32;
340 UINT32 *k = (UINT32 *)kp;
Damien Millerc331dbd2013-07-25 11:55:20 +1000341 const UINT32 *d = (const UINT32 *)dp;
Damien Millere45796f2007-06-11 14:01:42 +1000342 UINT32 d0,d1,d2,d3,d4,d5,d6,d7;
343 UINT32 k0,k1,k2,k3,k4,k5,k6,k7;
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000344
Damien Millere45796f2007-06-11 14:01:42 +1000345 h = *((UINT64 *)hp);
346 do {
347 d0 = LOAD_UINT32_LITTLE(d+0); d1 = LOAD_UINT32_LITTLE(d+1);
348 d2 = LOAD_UINT32_LITTLE(d+2); d3 = LOAD_UINT32_LITTLE(d+3);
349 d4 = LOAD_UINT32_LITTLE(d+4); d5 = LOAD_UINT32_LITTLE(d+5);
350 d6 = LOAD_UINT32_LITTLE(d+6); d7 = LOAD_UINT32_LITTLE(d+7);
351 k0 = *(k+0); k1 = *(k+1); k2 = *(k+2); k3 = *(k+3);
352 k4 = *(k+4); k5 = *(k+5); k6 = *(k+6); k7 = *(k+7);
353 h += MUL64((k0 + d0), (k4 + d4));
354 h += MUL64((k1 + d1), (k5 + d5));
355 h += MUL64((k2 + d2), (k6 + d6));
356 h += MUL64((k3 + d3), (k7 + d7));
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000357
Damien Millere45796f2007-06-11 14:01:42 +1000358 d += 8;
359 k += 8;
360 } while (--c);
361 *((UINT64 *)hp) = h;
362}
363
364#elif (UMAC_OUTPUT_LEN == 8)
365
Damien Millerc331dbd2013-07-25 11:55:20 +1000366static void nh_aux(void *kp, const void *dp, void *hp, UINT32 dlen)
Damien Millere45796f2007-06-11 14:01:42 +1000367/* Same as previous nh_aux, but two streams are handled in one pass,
368 * reading and writing 16 bytes of hash-state per call.
369 */
370{
371 UINT64 h1,h2;
372 UWORD c = dlen / 32;
373 UINT32 *k = (UINT32 *)kp;
Damien Millerc331dbd2013-07-25 11:55:20 +1000374 const UINT32 *d = (const UINT32 *)dp;
Damien Millere45796f2007-06-11 14:01:42 +1000375 UINT32 d0,d1,d2,d3,d4,d5,d6,d7;
376 UINT32 k0,k1,k2,k3,k4,k5,k6,k7,
377 k8,k9,k10,k11;
378
379 h1 = *((UINT64 *)hp);
380 h2 = *((UINT64 *)hp + 1);
381 k0 = *(k+0); k1 = *(k+1); k2 = *(k+2); k3 = *(k+3);
382 do {
383 d0 = LOAD_UINT32_LITTLE(d+0); d1 = LOAD_UINT32_LITTLE(d+1);
384 d2 = LOAD_UINT32_LITTLE(d+2); d3 = LOAD_UINT32_LITTLE(d+3);
385 d4 = LOAD_UINT32_LITTLE(d+4); d5 = LOAD_UINT32_LITTLE(d+5);
386 d6 = LOAD_UINT32_LITTLE(d+6); d7 = LOAD_UINT32_LITTLE(d+7);
387 k4 = *(k+4); k5 = *(k+5); k6 = *(k+6); k7 = *(k+7);
388 k8 = *(k+8); k9 = *(k+9); k10 = *(k+10); k11 = *(k+11);
389
390 h1 += MUL64((k0 + d0), (k4 + d4));
391 h2 += MUL64((k4 + d0), (k8 + d4));
392
393 h1 += MUL64((k1 + d1), (k5 + d5));
394 h2 += MUL64((k5 + d1), (k9 + d5));
395
396 h1 += MUL64((k2 + d2), (k6 + d6));
397 h2 += MUL64((k6 + d2), (k10 + d6));
398
399 h1 += MUL64((k3 + d3), (k7 + d7));
400 h2 += MUL64((k7 + d3), (k11 + d7));
401
402 k0 = k8; k1 = k9; k2 = k10; k3 = k11;
403
404 d += 8;
405 k += 8;
406 } while (--c);
407 ((UINT64 *)hp)[0] = h1;
408 ((UINT64 *)hp)[1] = h2;
409}
410
411#elif (UMAC_OUTPUT_LEN == 12)
412
Damien Millerc331dbd2013-07-25 11:55:20 +1000413static void nh_aux(void *kp, const void *dp, void *hp, UINT32 dlen)
Damien Millere45796f2007-06-11 14:01:42 +1000414/* Same as previous nh_aux, but two streams are handled in one pass,
415 * reading and writing 24 bytes of hash-state per call.
416*/
417{
418 UINT64 h1,h2,h3;
419 UWORD c = dlen / 32;
420 UINT32 *k = (UINT32 *)kp;
Damien Millerc331dbd2013-07-25 11:55:20 +1000421 const UINT32 *d = (const UINT32 *)dp;
Damien Millere45796f2007-06-11 14:01:42 +1000422 UINT32 d0,d1,d2,d3,d4,d5,d6,d7;
423 UINT32 k0,k1,k2,k3,k4,k5,k6,k7,
424 k8,k9,k10,k11,k12,k13,k14,k15;
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000425
Damien Millere45796f2007-06-11 14:01:42 +1000426 h1 = *((UINT64 *)hp);
427 h2 = *((UINT64 *)hp + 1);
428 h3 = *((UINT64 *)hp + 2);
429 k0 = *(k+0); k1 = *(k+1); k2 = *(k+2); k3 = *(k+3);
430 k4 = *(k+4); k5 = *(k+5); k6 = *(k+6); k7 = *(k+7);
431 do {
432 d0 = LOAD_UINT32_LITTLE(d+0); d1 = LOAD_UINT32_LITTLE(d+1);
433 d2 = LOAD_UINT32_LITTLE(d+2); d3 = LOAD_UINT32_LITTLE(d+3);
434 d4 = LOAD_UINT32_LITTLE(d+4); d5 = LOAD_UINT32_LITTLE(d+5);
435 d6 = LOAD_UINT32_LITTLE(d+6); d7 = LOAD_UINT32_LITTLE(d+7);
436 k8 = *(k+8); k9 = *(k+9); k10 = *(k+10); k11 = *(k+11);
437 k12 = *(k+12); k13 = *(k+13); k14 = *(k+14); k15 = *(k+15);
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000438
Damien Millere45796f2007-06-11 14:01:42 +1000439 h1 += MUL64((k0 + d0), (k4 + d4));
440 h2 += MUL64((k4 + d0), (k8 + d4));
441 h3 += MUL64((k8 + d0), (k12 + d4));
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000442
Damien Millere45796f2007-06-11 14:01:42 +1000443 h1 += MUL64((k1 + d1), (k5 + d5));
444 h2 += MUL64((k5 + d1), (k9 + d5));
445 h3 += MUL64((k9 + d1), (k13 + d5));
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000446
Damien Millere45796f2007-06-11 14:01:42 +1000447 h1 += MUL64((k2 + d2), (k6 + d6));
448 h2 += MUL64((k6 + d2), (k10 + d6));
449 h3 += MUL64((k10 + d2), (k14 + d6));
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000450
Damien Millere45796f2007-06-11 14:01:42 +1000451 h1 += MUL64((k3 + d3), (k7 + d7));
452 h2 += MUL64((k7 + d3), (k11 + d7));
453 h3 += MUL64((k11 + d3), (k15 + d7));
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000454
Damien Millere45796f2007-06-11 14:01:42 +1000455 k0 = k8; k1 = k9; k2 = k10; k3 = k11;
456 k4 = k12; k5 = k13; k6 = k14; k7 = k15;
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000457
Damien Millere45796f2007-06-11 14:01:42 +1000458 d += 8;
459 k += 8;
460 } while (--c);
461 ((UINT64 *)hp)[0] = h1;
462 ((UINT64 *)hp)[1] = h2;
463 ((UINT64 *)hp)[2] = h3;
464}
465
466#elif (UMAC_OUTPUT_LEN == 16)
467
Damien Millerc331dbd2013-07-25 11:55:20 +1000468static void nh_aux(void *kp, const void *dp, void *hp, UINT32 dlen)
Damien Millere45796f2007-06-11 14:01:42 +1000469/* Same as previous nh_aux, but two streams are handled in one pass,
470 * reading and writing 24 bytes of hash-state per call.
471*/
472{
473 UINT64 h1,h2,h3,h4;
474 UWORD c = dlen / 32;
475 UINT32 *k = (UINT32 *)kp;
Damien Millerc331dbd2013-07-25 11:55:20 +1000476 const UINT32 *d = (const UINT32 *)dp;
Damien Millere45796f2007-06-11 14:01:42 +1000477 UINT32 d0,d1,d2,d3,d4,d5,d6,d7;
478 UINT32 k0,k1,k2,k3,k4,k5,k6,k7,
479 k8,k9,k10,k11,k12,k13,k14,k15,
480 k16,k17,k18,k19;
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000481
Damien Millere45796f2007-06-11 14:01:42 +1000482 h1 = *((UINT64 *)hp);
483 h2 = *((UINT64 *)hp + 1);
484 h3 = *((UINT64 *)hp + 2);
485 h4 = *((UINT64 *)hp + 3);
486 k0 = *(k+0); k1 = *(k+1); k2 = *(k+2); k3 = *(k+3);
487 k4 = *(k+4); k5 = *(k+5); k6 = *(k+6); k7 = *(k+7);
488 do {
489 d0 = LOAD_UINT32_LITTLE(d+0); d1 = LOAD_UINT32_LITTLE(d+1);
490 d2 = LOAD_UINT32_LITTLE(d+2); d3 = LOAD_UINT32_LITTLE(d+3);
491 d4 = LOAD_UINT32_LITTLE(d+4); d5 = LOAD_UINT32_LITTLE(d+5);
492 d6 = LOAD_UINT32_LITTLE(d+6); d7 = LOAD_UINT32_LITTLE(d+7);
493 k8 = *(k+8); k9 = *(k+9); k10 = *(k+10); k11 = *(k+11);
494 k12 = *(k+12); k13 = *(k+13); k14 = *(k+14); k15 = *(k+15);
495 k16 = *(k+16); k17 = *(k+17); k18 = *(k+18); k19 = *(k+19);
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000496
Damien Millere45796f2007-06-11 14:01:42 +1000497 h1 += MUL64((k0 + d0), (k4 + d4));
498 h2 += MUL64((k4 + d0), (k8 + d4));
499 h3 += MUL64((k8 + d0), (k12 + d4));
500 h4 += MUL64((k12 + d0), (k16 + d4));
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000501
Damien Millere45796f2007-06-11 14:01:42 +1000502 h1 += MUL64((k1 + d1), (k5 + d5));
503 h2 += MUL64((k5 + d1), (k9 + d5));
504 h3 += MUL64((k9 + d1), (k13 + d5));
505 h4 += MUL64((k13 + d1), (k17 + d5));
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000506
Damien Millere45796f2007-06-11 14:01:42 +1000507 h1 += MUL64((k2 + d2), (k6 + d6));
508 h2 += MUL64((k6 + d2), (k10 + d6));
509 h3 += MUL64((k10 + d2), (k14 + d6));
510 h4 += MUL64((k14 + d2), (k18 + d6));
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000511
Damien Millere45796f2007-06-11 14:01:42 +1000512 h1 += MUL64((k3 + d3), (k7 + d7));
513 h2 += MUL64((k7 + d3), (k11 + d7));
514 h3 += MUL64((k11 + d3), (k15 + d7));
515 h4 += MUL64((k15 + d3), (k19 + d7));
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000516
Damien Millere45796f2007-06-11 14:01:42 +1000517 k0 = k8; k1 = k9; k2 = k10; k3 = k11;
518 k4 = k12; k5 = k13; k6 = k14; k7 = k15;
519 k8 = k16; k9 = k17; k10 = k18; k11 = k19;
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000520
Damien Millere45796f2007-06-11 14:01:42 +1000521 d += 8;
522 k += 8;
523 } while (--c);
524 ((UINT64 *)hp)[0] = h1;
525 ((UINT64 *)hp)[1] = h2;
526 ((UINT64 *)hp)[2] = h3;
527 ((UINT64 *)hp)[3] = h4;
528}
529
530/* ---------------------------------------------------------------------- */
531#endif /* UMAC_OUTPUT_LENGTH */
532/* ---------------------------------------------------------------------- */
533
534
535/* ---------------------------------------------------------------------- */
536
Damien Millerc331dbd2013-07-25 11:55:20 +1000537static void nh_transform(nh_ctx *hc, const UINT8 *buf, UINT32 nbytes)
Damien Millere45796f2007-06-11 14:01:42 +1000538/* This function is a wrapper for the primitive NH hash functions. It takes
539 * as argument "hc" the current hash context and a buffer which must be a
540 * multiple of L1_PAD_BOUNDARY. The key passed to nh_aux is offset
541 * appropriately according to how much message has been hashed already.
542 */
543{
544 UINT8 *key;
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000545
Damien Millere45796f2007-06-11 14:01:42 +1000546 key = hc->nh_key + hc->bytes_hashed;
547 nh_aux(key, buf, hc->state, nbytes);
548}
549
550/* ---------------------------------------------------------------------- */
551
Darren Tucker2c91b282008-06-13 12:40:55 +1000552#if (__LITTLE_ENDIAN__)
Damien Millere45796f2007-06-11 14:01:42 +1000553static void endian_convert(void *buf, UWORD bpw, UINT32 num_bytes)
554/* We endian convert the keys on little-endian computers to */
555/* compensate for the lack of big-endian memory reads during hashing. */
556{
557 UWORD iters = num_bytes / bpw;
558 if (bpw == 4) {
559 UINT32 *p = (UINT32 *)buf;
560 do {
561 *p = LOAD_UINT32_REVERSED(p);
562 p++;
563 } while (--iters);
564 } else if (bpw == 8) {
565 UINT32 *p = (UINT32 *)buf;
566 UINT32 t;
567 do {
568 t = LOAD_UINT32_REVERSED(p+1);
569 p[1] = LOAD_UINT32_REVERSED(p);
570 p[0] = t;
571 p += 2;
572 } while (--iters);
573 }
574}
Damien Millere45796f2007-06-11 14:01:42 +1000575#define endian_convert_if_le(x,y,z) endian_convert((x),(y),(z))
576#else
577#define endian_convert_if_le(x,y,z) do{}while(0) /* Do nothing */
578#endif
579
580/* ---------------------------------------------------------------------- */
581
582static void nh_reset(nh_ctx *hc)
583/* Reset nh_ctx to ready for hashing of new data */
584{
585 hc->bytes_hashed = 0;
586 hc->next_data_empty = 0;
587 hc->state[0] = 0;
588#if (UMAC_OUTPUT_LEN >= 8)
589 hc->state[1] = 0;
590#endif
591#if (UMAC_OUTPUT_LEN >= 12)
592 hc->state[2] = 0;
593#endif
594#if (UMAC_OUTPUT_LEN == 16)
595 hc->state[3] = 0;
596#endif
597
598}
599
600/* ---------------------------------------------------------------------- */
601
602static void nh_init(nh_ctx *hc, aes_int_key prf_key)
603/* Generate nh_key, endian convert and reset to be ready for hashing. */
604{
605 kdf(hc->nh_key, prf_key, 1, sizeof(hc->nh_key));
606 endian_convert_if_le(hc->nh_key, 4, sizeof(hc->nh_key));
607 nh_reset(hc);
608}
609
610/* ---------------------------------------------------------------------- */
611
Damien Millerc331dbd2013-07-25 11:55:20 +1000612static void nh_update(nh_ctx *hc, const UINT8 *buf, UINT32 nbytes)
Damien Millere45796f2007-06-11 14:01:42 +1000613/* Incorporate nbytes of data into a nh_ctx, buffer whatever is not an */
614/* even multiple of HASH_BUF_BYTES. */
615{
616 UINT32 i,j;
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000617
Damien Millere45796f2007-06-11 14:01:42 +1000618 j = hc->next_data_empty;
619 if ((j + nbytes) >= HASH_BUF_BYTES) {
620 if (j) {
621 i = HASH_BUF_BYTES - j;
622 memcpy(hc->data+j, buf, i);
623 nh_transform(hc,hc->data,HASH_BUF_BYTES);
624 nbytes -= i;
625 buf += i;
626 hc->bytes_hashed += HASH_BUF_BYTES;
627 }
628 if (nbytes >= HASH_BUF_BYTES) {
629 i = nbytes & ~(HASH_BUF_BYTES - 1);
630 nh_transform(hc, buf, i);
631 nbytes -= i;
632 buf += i;
633 hc->bytes_hashed += i;
634 }
635 j = 0;
636 }
637 memcpy(hc->data + j, buf, nbytes);
638 hc->next_data_empty = j + nbytes;
639}
640
641/* ---------------------------------------------------------------------- */
642
643static void zero_pad(UINT8 *p, int nbytes)
644{
645/* Write "nbytes" of zeroes, beginning at "p" */
646 if (nbytes >= (int)sizeof(UWORD)) {
647 while ((ptrdiff_t)p % sizeof(UWORD)) {
648 *p = 0;
649 nbytes--;
650 p++;
651 }
652 while (nbytes >= (int)sizeof(UWORD)) {
653 *(UWORD *)p = 0;
654 nbytes -= sizeof(UWORD);
655 p += sizeof(UWORD);
656 }
657 }
658 while (nbytes) {
659 *p = 0;
660 nbytes--;
661 p++;
662 }
663}
664
665/* ---------------------------------------------------------------------- */
666
667static void nh_final(nh_ctx *hc, UINT8 *result)
668/* After passing some number of data buffers to nh_update() for integration
669 * into an NH context, nh_final is called to produce a hash result. If any
670 * bytes are in the buffer hc->data, incorporate them into the
671 * NH context. Finally, add into the NH accumulation "state" the total number
672 * of bits hashed. The resulting numbers are written to the buffer "result".
673 * If nh_update was never called, L1_PAD_BOUNDARY zeroes are incorporated.
674 */
675{
676 int nh_len, nbits;
677
678 if (hc->next_data_empty != 0) {
679 nh_len = ((hc->next_data_empty + (L1_PAD_BOUNDARY - 1)) &
680 ~(L1_PAD_BOUNDARY - 1));
djm@openbsd.org@openbsd.org7f257bf2017-11-28 06:04:51 +0000681 zero_pad(hc->data + hc->next_data_empty,
Damien Millere45796f2007-06-11 14:01:42 +1000682 nh_len - hc->next_data_empty);
683 nh_transform(hc, hc->data, nh_len);
684 hc->bytes_hashed += hc->next_data_empty;
685 } else if (hc->bytes_hashed == 0) {
djm@openbsd.org2937dd02017-11-28 06:09:38 +0000686 nh_len = L1_PAD_BOUNDARY;
Damien Millere45796f2007-06-11 14:01:42 +1000687 zero_pad(hc->data, L1_PAD_BOUNDARY);
688 nh_transform(hc, hc->data, nh_len);
689 }
690
691 nbits = (hc->bytes_hashed << 3);
692 ((UINT64 *)result)[0] = ((UINT64 *)hc->state)[0] + nbits;
693#if (UMAC_OUTPUT_LEN >= 8)
694 ((UINT64 *)result)[1] = ((UINT64 *)hc->state)[1] + nbits;
695#endif
696#if (UMAC_OUTPUT_LEN >= 12)
697 ((UINT64 *)result)[2] = ((UINT64 *)hc->state)[2] + nbits;
698#endif
699#if (UMAC_OUTPUT_LEN == 16)
700 ((UINT64 *)result)[3] = ((UINT64 *)hc->state)[3] + nbits;
701#endif
702 nh_reset(hc);
703}
704
705/* ---------------------------------------------------------------------- */
706
Damien Millerc331dbd2013-07-25 11:55:20 +1000707static void nh(nh_ctx *hc, const UINT8 *buf, UINT32 padded_len,
Damien Millere45796f2007-06-11 14:01:42 +1000708 UINT32 unpadded_len, UINT8 *result)
709/* All-in-one nh_update() and nh_final() equivalent.
710 * Assumes that padded_len is divisible by L1_PAD_BOUNDARY and result is
711 * well aligned
712 */
713{
714 UINT32 nbits;
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000715
Damien Millere45796f2007-06-11 14:01:42 +1000716 /* Initialize the hash state */
717 nbits = (unpadded_len << 3);
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000718
Damien Millere45796f2007-06-11 14:01:42 +1000719 ((UINT64 *)result)[0] = nbits;
720#if (UMAC_OUTPUT_LEN >= 8)
721 ((UINT64 *)result)[1] = nbits;
722#endif
723#if (UMAC_OUTPUT_LEN >= 12)
724 ((UINT64 *)result)[2] = nbits;
725#endif
726#if (UMAC_OUTPUT_LEN == 16)
727 ((UINT64 *)result)[3] = nbits;
728#endif
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000729
Damien Millere45796f2007-06-11 14:01:42 +1000730 nh_aux(hc->nh_key, buf, result, padded_len);
731}
732
733/* ---------------------------------------------------------------------- */
734/* ---------------------------------------------------------------------- */
735/* ----- Begin UHASH Section -------------------------------------------- */
736/* ---------------------------------------------------------------------- */
737/* ---------------------------------------------------------------------- */
738
739/* UHASH is a multi-layered algorithm. Data presented to UHASH is first
740 * hashed by NH. The NH output is then hashed by a polynomial-hash layer
741 * unless the initial data to be hashed is short. After the polynomial-
742 * layer, an inner-product hash is used to produce the final UHASH output.
743 *
744 * UHASH provides two interfaces, one all-at-once and another where data
745 * buffers are presented sequentially. In the sequential interface, the
746 * UHASH client calls the routine uhash_update() as many times as necessary.
747 * When there is no more data to be fed to UHASH, the client calls
djm@openbsd.org@openbsd.org7f257bf2017-11-28 06:04:51 +0000748 * uhash_final() which
749 * calculates the UHASH output. Before beginning another UHASH calculation
750 * the uhash_reset() routine must be called. The all-at-once UHASH routine,
751 * uhash(), is equivalent to the sequence of calls uhash_update() and
752 * uhash_final(); however it is optimized and should be
753 * used whenever the sequential interface is not necessary.
754 *
755 * The routine uhash_init() initializes the uhash_ctx data structure and
Damien Millere45796f2007-06-11 14:01:42 +1000756 * must be called once, before any other UHASH routine.
djm@openbsd.org@openbsd.org7f257bf2017-11-28 06:04:51 +0000757 */
Damien Millere45796f2007-06-11 14:01:42 +1000758
759/* ---------------------------------------------------------------------- */
760/* ----- Constants and uhash_ctx ---------------------------------------- */
761/* ---------------------------------------------------------------------- */
762
763/* ---------------------------------------------------------------------- */
764/* ----- Poly hash and Inner-Product hash Constants --------------------- */
765/* ---------------------------------------------------------------------- */
766
767/* Primes and masks */
768#define p36 ((UINT64)0x0000000FFFFFFFFBull) /* 2^36 - 5 */
769#define p64 ((UINT64)0xFFFFFFFFFFFFFFC5ull) /* 2^64 - 59 */
770#define m36 ((UINT64)0x0000000FFFFFFFFFull) /* The low 36 of 64 bits */
771
772
773/* ---------------------------------------------------------------------- */
774
775typedef struct uhash_ctx {
776 nh_ctx hash; /* Hash context for L1 NH hash */
777 UINT64 poly_key_8[STREAMS]; /* p64 poly keys */
778 UINT64 poly_accum[STREAMS]; /* poly hash result */
779 UINT64 ip_keys[STREAMS*4]; /* Inner-product keys */
780 UINT32 ip_trans[STREAMS]; /* Inner-product translation */
781 UINT32 msg_len; /* Total length of data passed */
782 /* to uhash */
783} uhash_ctx;
784typedef struct uhash_ctx *uhash_ctx_t;
785
786/* ---------------------------------------------------------------------- */
787
788
789/* The polynomial hashes use Horner's rule to evaluate a polynomial one
790 * word at a time. As described in the specification, poly32 and poly64
791 * require keys from special domains. The following implementations exploit
792 * the special domains to avoid overflow. The results are not guaranteed to
793 * be within Z_p32 and Z_p64, but the Inner-Product hash implementation
794 * patches any errant values.
795 */
796
797static UINT64 poly64(UINT64 cur, UINT64 key, UINT64 data)
798{
799 UINT32 key_hi = (UINT32)(key >> 32),
800 key_lo = (UINT32)key,
801 cur_hi = (UINT32)(cur >> 32),
802 cur_lo = (UINT32)cur,
803 x_lo,
804 x_hi;
805 UINT64 X,T,res;
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000806
Damien Millere45796f2007-06-11 14:01:42 +1000807 X = MUL64(key_hi, cur_lo) + MUL64(cur_hi, key_lo);
808 x_lo = (UINT32)X;
809 x_hi = (UINT32)(X >> 32);
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000810
Damien Millere45796f2007-06-11 14:01:42 +1000811 res = (MUL64(key_hi, cur_hi) + x_hi) * 59 + MUL64(key_lo, cur_lo);
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000812
Damien Millere45796f2007-06-11 14:01:42 +1000813 T = ((UINT64)x_lo << 32);
814 res += T;
815 if (res < T)
816 res += 59;
817
818 res += data;
819 if (res < data)
820 res += 59;
821
822 return res;
823}
824
825
826/* Although UMAC is specified to use a ramped polynomial hash scheme, this
827 * implementation does not handle all ramp levels. Because we don't handle
828 * the ramp up to p128 modulus in this implementation, we are limited to
829 * 2^14 poly_hash() invocations per stream (for a total capacity of 2^24
830 * bytes input to UMAC per tag, ie. 16MB).
831 */
832static void poly_hash(uhash_ctx_t hc, UINT32 data_in[])
833{
834 int i;
835 UINT64 *data=(UINT64*)data_in;
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000836
Damien Millere45796f2007-06-11 14:01:42 +1000837 for (i = 0; i < STREAMS; i++) {
838 if ((UINT32)(data[i] >> 32) == 0xfffffffful) {
djm@openbsd.org@openbsd.org7f257bf2017-11-28 06:04:51 +0000839 hc->poly_accum[i] = poly64(hc->poly_accum[i],
Damien Millere45796f2007-06-11 14:01:42 +1000840 hc->poly_key_8[i], p64 - 1);
841 hc->poly_accum[i] = poly64(hc->poly_accum[i],
842 hc->poly_key_8[i], (data[i] - 59));
843 } else {
844 hc->poly_accum[i] = poly64(hc->poly_accum[i],
845 hc->poly_key_8[i], data[i]);
846 }
847 }
848}
849
850
851/* ---------------------------------------------------------------------- */
852
853
854/* The final step in UHASH is an inner-product hash. The poly hash
djm@openbsd.org001aa552018-04-10 00:10:49 +0000855 * produces a result not necessarily WORD_LEN bytes long. The inner-
Damien Millere45796f2007-06-11 14:01:42 +1000856 * product hash breaks the polyhash output into 16-bit chunks and
857 * multiplies each with a 36 bit key.
858 */
859
860static UINT64 ip_aux(UINT64 t, UINT64 *ipkp, UINT64 data)
861{
862 t = t + ipkp[0] * (UINT64)(UINT16)(data >> 48);
863 t = t + ipkp[1] * (UINT64)(UINT16)(data >> 32);
864 t = t + ipkp[2] * (UINT64)(UINT16)(data >> 16);
865 t = t + ipkp[3] * (UINT64)(UINT16)(data);
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000866
Damien Millere45796f2007-06-11 14:01:42 +1000867 return t;
868}
869
870static UINT32 ip_reduce_p36(UINT64 t)
871{
872/* Divisionless modular reduction */
873 UINT64 ret;
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000874
Damien Millere45796f2007-06-11 14:01:42 +1000875 ret = (t & m36) + 5 * (t >> 36);
876 if (ret >= p36)
877 ret -= p36;
878
879 /* return least significant 32 bits */
880 return (UINT32)(ret);
881}
882
883
884/* If the data being hashed by UHASH is no longer than L1_KEY_LEN, then
885 * the polyhash stage is skipped and ip_short is applied directly to the
886 * NH output.
887 */
888static void ip_short(uhash_ctx_t ahc, UINT8 *nh_res, u_char *res)
889{
890 UINT64 t;
891 UINT64 *nhp = (UINT64 *)nh_res;
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000892
Damien Millere45796f2007-06-11 14:01:42 +1000893 t = ip_aux(0,ahc->ip_keys, nhp[0]);
894 STORE_UINT32_BIG((UINT32 *)res+0, ip_reduce_p36(t) ^ ahc->ip_trans[0]);
895#if (UMAC_OUTPUT_LEN >= 8)
896 t = ip_aux(0,ahc->ip_keys+4, nhp[1]);
897 STORE_UINT32_BIG((UINT32 *)res+1, ip_reduce_p36(t) ^ ahc->ip_trans[1]);
898#endif
899#if (UMAC_OUTPUT_LEN >= 12)
900 t = ip_aux(0,ahc->ip_keys+8, nhp[2]);
901 STORE_UINT32_BIG((UINT32 *)res+2, ip_reduce_p36(t) ^ ahc->ip_trans[2]);
902#endif
903#if (UMAC_OUTPUT_LEN == 16)
904 t = ip_aux(0,ahc->ip_keys+12, nhp[3]);
905 STORE_UINT32_BIG((UINT32 *)res+3, ip_reduce_p36(t) ^ ahc->ip_trans[3]);
906#endif
907}
908
909/* If the data being hashed by UHASH is longer than L1_KEY_LEN, then
910 * the polyhash stage is not skipped and ip_long is applied to the
911 * polyhash output.
912 */
913static void ip_long(uhash_ctx_t ahc, u_char *res)
914{
915 int i;
916 UINT64 t;
917
918 for (i = 0; i < STREAMS; i++) {
919 /* fix polyhash output not in Z_p64 */
920 if (ahc->poly_accum[i] >= p64)
921 ahc->poly_accum[i] -= p64;
922 t = ip_aux(0,ahc->ip_keys+(i*4), ahc->poly_accum[i]);
djm@openbsd.org@openbsd.org7f257bf2017-11-28 06:04:51 +0000923 STORE_UINT32_BIG((UINT32 *)res+i,
Damien Millere45796f2007-06-11 14:01:42 +1000924 ip_reduce_p36(t) ^ ahc->ip_trans[i]);
925 }
926}
927
928
929/* ---------------------------------------------------------------------- */
930
931/* ---------------------------------------------------------------------- */
932
933/* Reset uhash context for next hash session */
934static int uhash_reset(uhash_ctx_t pc)
935{
936 nh_reset(&pc->hash);
937 pc->msg_len = 0;
938 pc->poly_accum[0] = 1;
939#if (UMAC_OUTPUT_LEN >= 8)
940 pc->poly_accum[1] = 1;
941#endif
942#if (UMAC_OUTPUT_LEN >= 12)
943 pc->poly_accum[2] = 1;
944#endif
945#if (UMAC_OUTPUT_LEN == 16)
946 pc->poly_accum[3] = 1;
947#endif
948 return 1;
949}
950
951/* ---------------------------------------------------------------------- */
952
953/* Given a pointer to the internal key needed by kdf() and a uhash context,
954 * initialize the NH context and generate keys needed for poly and inner-
955 * product hashing. All keys are endian adjusted in memory so that native
956 * loads cause correct keys to be in registers during calculation.
957 */
958static void uhash_init(uhash_ctx_t ahc, aes_int_key prf_key)
959{
960 int i;
961 UINT8 buf[(8*STREAMS+4)*sizeof(UINT64)];
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000962
Damien Millere45796f2007-06-11 14:01:42 +1000963 /* Zero the entire uhash context */
964 memset(ahc, 0, sizeof(uhash_ctx));
965
966 /* Initialize the L1 hash */
967 nh_init(&ahc->hash, prf_key);
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000968
Damien Millere45796f2007-06-11 14:01:42 +1000969 /* Setup L2 hash variables */
970 kdf(buf, prf_key, 2, sizeof(buf)); /* Fill buffer with index 1 key */
971 for (i = 0; i < STREAMS; i++) {
972 /* Fill keys from the buffer, skipping bytes in the buffer not
973 * used by this implementation. Endian reverse the keys if on a
974 * little-endian computer.
975 */
976 memcpy(ahc->poly_key_8+i, buf+24*i, 8);
977 endian_convert_if_le(ahc->poly_key_8+i, 8, 8);
978 /* Mask the 64-bit keys to their special domain */
979 ahc->poly_key_8[i] &= ((UINT64)0x01ffffffu << 32) + 0x01ffffffu;
980 ahc->poly_accum[i] = 1; /* Our polyhash prepends a non-zero word */
981 }
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000982
Damien Millere45796f2007-06-11 14:01:42 +1000983 /* Setup L3-1 hash variables */
984 kdf(buf, prf_key, 3, sizeof(buf)); /* Fill buffer with index 2 key */
985 for (i = 0; i < STREAMS; i++)
986 memcpy(ahc->ip_keys+4*i, buf+(8*i+4)*sizeof(UINT64),
987 4*sizeof(UINT64));
djm@openbsd.org@openbsd.org7f257bf2017-11-28 06:04:51 +0000988 endian_convert_if_le(ahc->ip_keys, sizeof(UINT64),
Damien Millere45796f2007-06-11 14:01:42 +1000989 sizeof(ahc->ip_keys));
990 for (i = 0; i < STREAMS*4; i++)
991 ahc->ip_keys[i] %= p36; /* Bring into Z_p36 */
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +0000992
Damien Millere45796f2007-06-11 14:01:42 +1000993 /* Setup L3-2 hash variables */
994 /* Fill buffer with index 4 key */
995 kdf(ahc->ip_trans, prf_key, 4, STREAMS * sizeof(UINT32));
996 endian_convert_if_le(ahc->ip_trans, sizeof(UINT32),
997 STREAMS * sizeof(UINT32));
markus@openbsd.org1e0cdf82017-05-31 08:09:45 +0000998 explicit_bzero(buf, sizeof(buf));
Damien Millere45796f2007-06-11 14:01:42 +1000999}
1000
1001/* ---------------------------------------------------------------------- */
1002
1003#if 0
1004static uhash_ctx_t uhash_alloc(u_char key[])
1005{
1006/* Allocate memory and force to a 16-byte boundary. */
1007 uhash_ctx_t ctx;
1008 u_char bytes_to_add;
1009 aes_int_key prf_key;
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +00001010
Damien Millere45796f2007-06-11 14:01:42 +10001011 ctx = (uhash_ctx_t)malloc(sizeof(uhash_ctx)+ALLOC_BOUNDARY);
1012 if (ctx) {
1013 if (ALLOC_BOUNDARY) {
1014 bytes_to_add = ALLOC_BOUNDARY -
1015 ((ptrdiff_t)ctx & (ALLOC_BOUNDARY -1));
1016 ctx = (uhash_ctx_t)((u_char *)ctx + bytes_to_add);
1017 *((u_char *)ctx - 1) = bytes_to_add;
1018 }
1019 aes_key_setup(key,prf_key);
1020 uhash_init(ctx, prf_key);
1021 }
1022 return (ctx);
1023}
1024#endif
1025
1026/* ---------------------------------------------------------------------- */
1027
1028#if 0
1029static int uhash_free(uhash_ctx_t ctx)
1030{
1031/* Free memory allocated by uhash_alloc */
1032 u_char bytes_to_sub;
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +00001033
Damien Millere45796f2007-06-11 14:01:42 +10001034 if (ctx) {
1035 if (ALLOC_BOUNDARY) {
1036 bytes_to_sub = *((u_char *)ctx - 1);
1037 ctx = (uhash_ctx_t)((u_char *)ctx - bytes_to_sub);
1038 }
1039 free(ctx);
1040 }
1041 return (1);
1042}
1043#endif
1044/* ---------------------------------------------------------------------- */
1045
Damien Millerc331dbd2013-07-25 11:55:20 +10001046static int uhash_update(uhash_ctx_t ctx, const u_char *input, long len)
Damien Millere45796f2007-06-11 14:01:42 +10001047/* Given len bytes of data, we parse it into L1_KEY_LEN chunks and
1048 * hash each one with NH, calling the polyhash on each NH output.
1049 */
1050{
1051 UWORD bytes_hashed, bytes_remaining;
Damien Miller0f30c872008-05-19 16:07:45 +10001052 UINT64 result_buf[STREAMS];
1053 UINT8 *nh_result = (UINT8 *)&result_buf;
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +00001054
Damien Millere45796f2007-06-11 14:01:42 +10001055 if (ctx->msg_len + len <= L1_KEY_LEN) {
Damien Millerc331dbd2013-07-25 11:55:20 +10001056 nh_update(&ctx->hash, (const UINT8 *)input, len);
Damien Millere45796f2007-06-11 14:01:42 +10001057 ctx->msg_len += len;
1058 } else {
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +00001059
Damien Millere45796f2007-06-11 14:01:42 +10001060 bytes_hashed = ctx->msg_len % L1_KEY_LEN;
1061 if (ctx->msg_len == L1_KEY_LEN)
1062 bytes_hashed = L1_KEY_LEN;
1063
1064 if (bytes_hashed + len >= L1_KEY_LEN) {
1065
1066 /* If some bytes have been passed to the hash function */
1067 /* then we want to pass at most (L1_KEY_LEN - bytes_hashed) */
1068 /* bytes to complete the current nh_block. */
1069 if (bytes_hashed) {
1070 bytes_remaining = (L1_KEY_LEN - bytes_hashed);
Damien Millerc331dbd2013-07-25 11:55:20 +10001071 nh_update(&ctx->hash, (const UINT8 *)input, bytes_remaining);
Damien Millere45796f2007-06-11 14:01:42 +10001072 nh_final(&ctx->hash, nh_result);
1073 ctx->msg_len += bytes_remaining;
1074 poly_hash(ctx,(UINT32 *)nh_result);
1075 len -= bytes_remaining;
1076 input += bytes_remaining;
1077 }
1078
1079 /* Hash directly from input stream if enough bytes */
1080 while (len >= L1_KEY_LEN) {
Damien Millerc331dbd2013-07-25 11:55:20 +10001081 nh(&ctx->hash, (const UINT8 *)input, L1_KEY_LEN,
Damien Millere45796f2007-06-11 14:01:42 +10001082 L1_KEY_LEN, nh_result);
1083 ctx->msg_len += L1_KEY_LEN;
1084 len -= L1_KEY_LEN;
1085 input += L1_KEY_LEN;
1086 poly_hash(ctx,(UINT32 *)nh_result);
1087 }
1088 }
1089
1090 /* pass remaining < L1_KEY_LEN bytes of input data to NH */
1091 if (len) {
Damien Millerc331dbd2013-07-25 11:55:20 +10001092 nh_update(&ctx->hash, (const UINT8 *)input, len);
Damien Millere45796f2007-06-11 14:01:42 +10001093 ctx->msg_len += len;
1094 }
1095 }
1096
1097 return (1);
1098}
1099
1100/* ---------------------------------------------------------------------- */
1101
1102static int uhash_final(uhash_ctx_t ctx, u_char *res)
1103/* Incorporate any pending data, pad, and generate tag */
1104{
Damien Miller0f30c872008-05-19 16:07:45 +10001105 UINT64 result_buf[STREAMS];
1106 UINT8 *nh_result = (UINT8 *)&result_buf;
Damien Millere45796f2007-06-11 14:01:42 +10001107
1108 if (ctx->msg_len > L1_KEY_LEN) {
1109 if (ctx->msg_len % L1_KEY_LEN) {
1110 nh_final(&ctx->hash, nh_result);
1111 poly_hash(ctx,(UINT32 *)nh_result);
1112 }
1113 ip_long(ctx, res);
1114 } else {
1115 nh_final(&ctx->hash, nh_result);
1116 ip_short(ctx,nh_result, res);
1117 }
1118 uhash_reset(ctx);
1119 return (1);
1120}
1121
1122/* ---------------------------------------------------------------------- */
1123
1124#if 0
1125static int uhash(uhash_ctx_t ahc, u_char *msg, long len, u_char *res)
1126/* assumes that msg is in a writable buffer of length divisible by */
1127/* L1_PAD_BOUNDARY. Bytes beyond msg[len] may be zeroed. */
1128{
1129 UINT8 nh_result[STREAMS*sizeof(UINT64)];
1130 UINT32 nh_len;
1131 int extra_zeroes_needed;
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +00001132
Damien Millere45796f2007-06-11 14:01:42 +10001133 /* If the message to be hashed is no longer than L1_HASH_LEN, we skip
1134 * the polyhash.
1135 */
1136 if (len <= L1_KEY_LEN) {
djm@openbsd.org2937dd02017-11-28 06:09:38 +00001137 if (len == 0) /* If zero length messages will not */
1138 nh_len = L1_PAD_BOUNDARY; /* be seen, comment out this case */
1139 else
1140 nh_len = ((len + (L1_PAD_BOUNDARY - 1)) & ~(L1_PAD_BOUNDARY - 1));
Damien Millere45796f2007-06-11 14:01:42 +10001141 extra_zeroes_needed = nh_len - len;
1142 zero_pad((UINT8 *)msg + len, extra_zeroes_needed);
1143 nh(&ahc->hash, (UINT8 *)msg, nh_len, len, nh_result);
1144 ip_short(ahc,nh_result, res);
1145 } else {
1146 /* Otherwise, we hash each L1_KEY_LEN chunk with NH, passing the NH
1147 * output to poly_hash().
1148 */
1149 do {
1150 nh(&ahc->hash, (UINT8 *)msg, L1_KEY_LEN, L1_KEY_LEN, nh_result);
1151 poly_hash(ahc,(UINT32 *)nh_result);
1152 len -= L1_KEY_LEN;
1153 msg += L1_KEY_LEN;
1154 } while (len >= L1_KEY_LEN);
1155 if (len) {
1156 nh_len = ((len + (L1_PAD_BOUNDARY - 1)) & ~(L1_PAD_BOUNDARY - 1));
1157 extra_zeroes_needed = nh_len - len;
1158 zero_pad((UINT8 *)msg + len, extra_zeroes_needed);
1159 nh(&ahc->hash, (UINT8 *)msg, nh_len, len, nh_result);
1160 poly_hash(ahc,(UINT32 *)nh_result);
1161 }
1162
1163 ip_long(ahc, res);
1164 }
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +00001165
Damien Millere45796f2007-06-11 14:01:42 +10001166 uhash_reset(ahc);
1167 return 1;
1168}
1169#endif
1170
1171/* ---------------------------------------------------------------------- */
1172/* ---------------------------------------------------------------------- */
1173/* ----- Begin UMAC Section --------------------------------------------- */
1174/* ---------------------------------------------------------------------- */
1175/* ---------------------------------------------------------------------- */
1176
1177/* The UMAC interface has two interfaces, an all-at-once interface where
1178 * the entire message to be authenticated is passed to UMAC in one buffer,
djm@openbsd.org@openbsd.org7f257bf2017-11-28 06:04:51 +00001179 * and a sequential interface where the message is presented a little at a
Damien Millere45796f2007-06-11 14:01:42 +10001180 * time. The all-at-once is more optimaized than the sequential version and
djm@openbsd.org@openbsd.org7f257bf2017-11-28 06:04:51 +00001181 * should be preferred when the sequential interface is not required.
Damien Millere45796f2007-06-11 14:01:42 +10001182 */
1183struct umac_ctx {
1184 uhash_ctx hash; /* Hash function for message compression */
1185 pdf_ctx pdf; /* PDF for hashed output */
1186 void *free_ptr; /* Address to free this struct via */
1187} umac_ctx;
1188
1189/* ---------------------------------------------------------------------- */
1190
1191#if 0
1192int umac_reset(struct umac_ctx *ctx)
1193/* Reset the hash function to begin a new authentication. */
1194{
1195 uhash_reset(&ctx->hash);
1196 return (1);
1197}
1198#endif
1199
1200/* ---------------------------------------------------------------------- */
1201
1202int umac_delete(struct umac_ctx *ctx)
1203/* Deallocate the ctx structure */
1204{
1205 if (ctx) {
1206 if (ALLOC_BOUNDARY)
1207 ctx = (struct umac_ctx *)ctx->free_ptr;
jsg@openbsd.orgd5ba1c02020-02-26 13:40:09 +00001208 freezero(ctx, sizeof(*ctx) + ALLOC_BOUNDARY);
Damien Millere45796f2007-06-11 14:01:42 +10001209 }
1210 return (1);
1211}
1212
1213/* ---------------------------------------------------------------------- */
1214
Damien Millerc331dbd2013-07-25 11:55:20 +10001215struct umac_ctx *umac_new(const u_char key[])
djm@openbsd.org@openbsd.org7f257bf2017-11-28 06:04:51 +00001216/* Dynamically allocate a umac_ctx struct, initialize variables,
Damien Millere45796f2007-06-11 14:01:42 +10001217 * generate subkeys from key. Align to 16-byte boundary.
1218 */
1219{
1220 struct umac_ctx *ctx, *octx;
1221 size_t bytes_to_add;
1222 aes_int_key prf_key;
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +00001223
Damien Miller6c81fee2013-11-08 12:19:55 +11001224 octx = ctx = xcalloc(1, sizeof(*ctx) + ALLOC_BOUNDARY);
Damien Millere45796f2007-06-11 14:01:42 +10001225 if (ctx) {
1226 if (ALLOC_BOUNDARY) {
1227 bytes_to_add = ALLOC_BOUNDARY -
1228 ((ptrdiff_t)ctx & (ALLOC_BOUNDARY - 1));
1229 ctx = (struct umac_ctx *)((u_char *)ctx + bytes_to_add);
1230 }
1231 ctx->free_ptr = octx;
Damien Millerc331dbd2013-07-25 11:55:20 +10001232 aes_key_setup(key, prf_key);
Damien Millere45796f2007-06-11 14:01:42 +10001233 pdf_init(&ctx->pdf, prf_key);
1234 uhash_init(&ctx->hash, prf_key);
markus@openbsd.org1e0cdf82017-05-31 08:09:45 +00001235 explicit_bzero(prf_key, sizeof(prf_key));
Damien Millere45796f2007-06-11 14:01:42 +10001236 }
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +00001237
Damien Millere45796f2007-06-11 14:01:42 +10001238 return (ctx);
1239}
1240
1241/* ---------------------------------------------------------------------- */
1242
Damien Millerc331dbd2013-07-25 11:55:20 +10001243int umac_final(struct umac_ctx *ctx, u_char tag[], const u_char nonce[8])
Damien Millere45796f2007-06-11 14:01:42 +10001244/* Incorporate any pending data, pad, and generate tag */
1245{
1246 uhash_final(&ctx->hash, (u_char *)tag);
Damien Millerc331dbd2013-07-25 11:55:20 +10001247 pdf_gen_xor(&ctx->pdf, (const UINT8 *)nonce, (UINT8 *)tag);
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +00001248
Damien Millere45796f2007-06-11 14:01:42 +10001249 return (1);
1250}
1251
1252/* ---------------------------------------------------------------------- */
1253
Damien Millerc331dbd2013-07-25 11:55:20 +10001254int umac_update(struct umac_ctx *ctx, const u_char *input, long len)
Damien Millere45796f2007-06-11 14:01:42 +10001255/* Given len bytes of data, we parse it into L1_KEY_LEN chunks and */
1256/* hash each one, calling the PDF on the hashed output whenever the hash- */
1257/* output buffer is full. */
1258{
1259 uhash_update(&ctx->hash, input, len);
1260 return (1);
1261}
1262
1263/* ---------------------------------------------------------------------- */
1264
1265#if 0
djm@openbsd.org@openbsd.org7f257bf2017-11-28 06:04:51 +00001266int umac(struct umac_ctx *ctx, u_char *input,
Damien Millere45796f2007-06-11 14:01:42 +10001267 long len, u_char tag[],
1268 u_char nonce[8])
1269/* All-in-one version simply calls umac_update() and umac_final(). */
1270{
1271 uhash(&ctx->hash, input, len, (u_char *)tag);
1272 pdf_gen_xor(&ctx->pdf, (UINT8 *)nonce, (UINT8 *)tag);
djm@openbsd.org@openbsd.orgd2135472017-10-27 01:01:17 +00001273
Damien Millere45796f2007-06-11 14:01:42 +10001274 return (1);
1275}
1276#endif
1277
1278/* ---------------------------------------------------------------------- */
1279/* ---------------------------------------------------------------------- */
1280/* ----- End UMAC Section ----------------------------------------------- */
1281/* ---------------------------------------------------------------------- */
1282/* ---------------------------------------------------------------------- */