diff options
| author | beatrice <beatrice@dangofactory.net> | 2026-11-22 20:02:54 +0900 |
|---|---|---|
| committer | beatrice <beatrice@dangofactory.net> | 2026-11-22 20:02:54 +0900 |
| commit | df92ccb9f67b8fb9aa6cc519f88599632d0cd4bb (patch) | |
| tree | 8b065509c7ba5a6e4b2f07a29ce2d701a83543e3 /misc/umac | |
| parent | ef717fe1c6dba4e964474aca92ea8e3e94b524c6 (diff) | |
| download | nettle-master.tar.gz nettle-master.zip | |
Release tarball nettle-3.10.1.tar.gz (dist-generated files / local differences from tag)HEADlocal/nettlemaster
Diffstat (limited to 'misc/umac')
| -rw-r--r-- | misc/umac/.gitignore | 1 | ||||
| -rw-r--r-- | misc/umac/Makefile | 4 | ||||
| -rwxr-xr-x | misc/umac/mkvectors | 90 | ||||
| -rw-r--r-- | misc/umac/repeat.py | 19 | ||||
| -rw-r--r-- | misc/umac/rijndael.py | 376 | ||||
| -rw-r--r-- | misc/umac/umac.py | 154 | ||||
| -rw-r--r-- | misc/umac/vectors.out | 432 |
7 files changed, 0 insertions, 1076 deletions
diff --git a/misc/umac/.gitignore b/misc/umac/.gitignore deleted file mode 100644 index 0d20b648..00000000 --- a/misc/umac/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.pyc diff --git a/misc/umac/Makefile b/misc/umac/Makefile deleted file mode 100644 index 8a932c2d..00000000 --- a/misc/umac/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -all: vectors.out - -vectors.out: mkvectors umac.py rijndael.py - ./mkvectors > vectors.out diff --git a/misc/umac/mkvectors b/misc/umac/mkvectors deleted file mode 100755 index 50e3ab64..00000000 --- a/misc/umac/mkvectors +++ /dev/null @@ -1,90 +0,0 @@ -#! /bin/bash - -set -e - -vector () { - nonce="$1" - length="$2" - data="$3" - echo "nonce:" $nonce - echo "msg length:" $length - if [ $length != "`expr length "$data"`" ] ; then - echo "data (repeated):" $data - else - echo "data:" $data - fi - for tag_len in 32 64 96 128 ; do - tag=`python repeat.py "$data" "$length" | python umac.py "$tag_len" "$nonce"` - echo "tag$tag_len:" $tag - done - echo -} - -NONCE=bcdefghi - -# RFC 4418 test vectors -vector $NONCE 0 "" -vector $NONCE 3 "a" -vector $NONCE 1024 "a" -vector $NONCE 32768 "a" -vector $NONCE 1048576 "a" -vector $NONCE 33554432 "a" -vector $NONCE 3 "abc" -vector $nonce 1500 "abc" - -DATA=def -NONCE=bcdefghijklmnopq - -vector ${NONCE:0:1} 0 $DATA -vector ${NONCE:0:2} 1 $DATA -vector ${NONCE:0:3} 2 $DATA -vector ${NONCE:0:4} 3 $DATA -vector ${NONCE:0:5} 4 $DATA - -vector ${NONCE:0:6} 1020 $DATA -vector ${NONCE:0:7} 1021 $DATA -vector ${NONCE:0:8} 1022 $DATA -vector ${NONCE:0:9} 1023 $DATA -vector ${NONCE:0:10} 1024 $DATA -vector ${NONCE:0:11} 1025 $DATA -vector ${NONCE:0:12} 1026 $DATA -vector ${NONCE:0:13} 1027 $DATA - -vector ${NONCE:0:14} 2046 $DATA -vector ${NONCE:0:15} 2047 $DATA -vector ${NONCE:0:16} 2048 $DATA -vector ${NONCE:0:1} 2049 $DATA -vector ${NONCE:0:2} 2050 $DATA - -vector ${NONCE:0:3} 16777212 $DATA -vector ${NONCE:0:4} 16777213 $DATA -vector ${NONCE:0:5} 16777214 $DATA -vector ${NONCE:0:6} 16777215 $DATA -vector ${NONCE:0:7} 16777216 $DATA -vector ${NONCE:0:8} 16777217 $DATA - -vector ${NONCE:0:9} 16778239 $DATA -vector ${NONCE:0:10} 16778240 $DATA -vector ${NONCE:0:11} 16778241 $DATA -vector ${NONCE:0:12} 16778242 $DATA -vector ${NONCE:0:13} 16778243 $DATA -vector ${NONCE:0:14} 16778244 $DATA - -vector '#00000000000000000000000000000000' 4 zero -vector '#00000000000000000000000000000001' 4 zero -vector '#00000000000000000000000000000002' 4 zero -vector '#00000000000000000000000000000003' 4 zero -vector '#00000000000000000000000000000004' 4 zero -vector '#00000000000000000000000000000005' 4 zero - -vector 'a' 7 nonce-a -vector 'b' 7 nonce-a -vector 'c' 7 nonce-a -vector 'd' 7 nonce-a -vector 'e' 7 nonce-a - -vector '#beafcafe' 15 nonce-beaf-cafe -vector '#beafcaff' 15 nonce-beaf-cafe -vector '#beafcb00' 15 nonce-beaf-cafe -vector '#beafcb01' 15 nonce-beaf-cafe -vector '#beafcb02' 15 nonce-beaf-cafe diff --git a/misc/umac/repeat.py b/misc/umac/repeat.py deleted file mode 100644 index 0bcf52ef..00000000 --- a/misc/umac/repeat.py +++ /dev/null @@ -1,19 +0,0 @@ -import sys - -if len(sys.argv) < 3: - sys.stderr.write('Usage: repeat [string] [length]\n') - sys.exit(1) - -s = sys.argv[1] -length = int(sys.argv[2]) -if length > 0: - if length > 1024: - while len(s) < 1024: - s = s + s; - while length > len(s): - sys.stdout.write(s) - length -= len(s) - - sys.stdout.write(s[:length]) - - diff --git a/misc/umac/rijndael.py b/misc/umac/rijndael.py deleted file mode 100644 index fa025c6f..00000000 --- a/misc/umac/rijndael.py +++ /dev/null @@ -1,376 +0,0 @@ -""" -A pure python (slow) implementation of rijndael with a decent interface - -To include - - -from rijndael import rijndael - -To do a key setup - - -r = rijndael(key, block_size = 16) - -key must be a string of length 16, 24, or 32 -blocksize must be 16, 24, or 32. Default is 16 - -To use - - -ciphertext = r.encrypt(plaintext) -plaintext = r.decrypt(ciphertext) - -If any strings are of the wrong length a ValueError is thrown -""" - -# ported from the Java reference code by Bram Cohen, April 2001 -# this code is public domain, unless someone makes -# an intellectual property claim against the reference -# code, in which case it can be made public domain by -# deleting all the comments and renaming all the variables - -import copy -import string - -shifts = [[[0, 0], [1, 3], [2, 2], [3, 1]], - [[0, 0], [1, 5], [2, 4], [3, 3]], - [[0, 0], [1, 7], [3, 5], [4, 4]]] - -# [keysize][block_size] -num_rounds = {16: {16: 10, 24: 12, 32: 14}, 24: {16: 12, 24: 12, 32: 14}, 32: {16: 14, 24: 14, 32: 14}} - -A = [[1, 1, 1, 1, 1, 0, 0, 0], - [0, 1, 1, 1, 1, 1, 0, 0], - [0, 0, 1, 1, 1, 1, 1, 0], - [0, 0, 0, 1, 1, 1, 1, 1], - [1, 0, 0, 0, 1, 1, 1, 1], - [1, 1, 0, 0, 0, 1, 1, 1], - [1, 1, 1, 0, 0, 0, 1, 1], - [1, 1, 1, 1, 0, 0, 0, 1]] - -# produce log and alog tables, needed for multiplying in the -# field GF(2^m) (generator = 3) -alog = [1] -for i in xrange(255): - j = (alog[-1] << 1) ^ alog[-1] - if j & 0x100 != 0: - j ^= 0x11B - alog.append(j) - -log = [0] * 256 -for i in xrange(1, 255): - log[alog[i]] = i - -# multiply two elements of GF(2^m) -def mul(a, b): - if a == 0 or b == 0: - return 0 - return alog[(log[a & 0xFF] + log[b & 0xFF]) % 255] - -# substitution box based on F^{-1}(x) -box = [[0] * 8 for i in xrange(256)] -box[1][7] = 1 -for i in xrange(2, 256): - j = alog[255 - log[i]] - for t in xrange(8): - box[i][t] = (j >> (7 - t)) & 0x01 - -B = [0, 1, 1, 0, 0, 0, 1, 1] - -# affine transform: box[i] <- B + A*box[i] -cox = [[0] * 8 for i in xrange(256)] -for i in xrange(256): - for t in xrange(8): - cox[i][t] = B[t] - for j in xrange(8): - cox[i][t] ^= A[t][j] * box[i][j] - -# S-boxes and inverse S-boxes -S = [0] * 256 -Si = [0] * 256 -for i in xrange(256): - S[i] = cox[i][0] << 7 - for t in xrange(1, 8): - S[i] ^= cox[i][t] << (7-t) - Si[S[i] & 0xFF] = i - -# T-boxes -G = [[2, 1, 1, 3], - [3, 2, 1, 1], - [1, 3, 2, 1], - [1, 1, 3, 2]] - -AA = [[0] * 8 for i in xrange(4)] - -for i in xrange(4): - for j in xrange(4): - AA[i][j] = G[i][j] - AA[i][i+4] = 1 - -for i in xrange(4): - pivot = AA[i][i] - if pivot == 0: - t = i + 1 - while AA[t][i] == 0 and t < 4: - t += 1 - assert t != 4, 'G matrix must be invertible' - for j in xrange(8): - AA[i][j], AA[t][j] = AA[t][j], AA[i][j] - pivot = AA[i][i] - for j in xrange(8): - if AA[i][j] != 0: - AA[i][j] = alog[(255 + log[AA[i][j] & 0xFF] - log[pivot & 0xFF]) % 255] - for t in xrange(4): - if i != t: - for j in xrange(i+1, 8): - AA[t][j] ^= mul(AA[i][j], AA[t][i]) - AA[t][i] = 0 - -iG = [[0] * 4 for i in xrange(4)] - -for i in xrange(4): - for j in xrange(4): - iG[i][j] = AA[i][j + 4] - -def mul4(a, bs): - if a == 0: - return 0 - r = 0 - for b in bs: - r <<= 8 - if b != 0: - r = r | mul(a, b) - return r - -T1 = [] -T2 = [] -T3 = [] -T4 = [] -T5 = [] -T6 = [] -T7 = [] -T8 = [] -U1 = [] -U2 = [] -U3 = [] -U4 = [] - -for t in xrange(256): - s = S[t] - T1.append(mul4(s, G[0])) - T2.append(mul4(s, G[1])) - T3.append(mul4(s, G[2])) - T4.append(mul4(s, G[3])) - - s = Si[t] - T5.append(mul4(s, iG[0])) - T6.append(mul4(s, iG[1])) - T7.append(mul4(s, iG[2])) - T8.append(mul4(s, iG[3])) - - U1.append(mul4(t, iG[0])) - U2.append(mul4(t, iG[1])) - U3.append(mul4(t, iG[2])) - U4.append(mul4(t, iG[3])) - -# round constants -rcon = [1] -r = 1 -for t in xrange(1, 30): - r = mul(2, r) - rcon.append(r) - -del A -del AA -del pivot -del B -del G -del box -del log -del alog -del i -del j -del r -del s -del t -del mul -del mul4 -del cox -del iG - -class rijndael: - def __init__(self, key, block_size = 16): - if block_size != 16 and block_size != 24 and block_size != 32: - raise ValueError('Invalid block size: ' + str(block_size)) - if len(key) != 16 and len(key) != 24 and len(key) != 32: - raise ValueError('Invalid key size: ' + str(len(key))) - self.block_size = block_size - - ROUNDS = num_rounds[len(key)][block_size] - BC = block_size / 4 - # encryption round keys - Ke = [[0] * BC for i in xrange(ROUNDS + 1)] - # decryption round keys - Kd = [[0] * BC for i in xrange(ROUNDS + 1)] - ROUND_KEY_COUNT = (ROUNDS + 1) * BC - KC = len(key) / 4 - - # copy user material bytes into temporary ints - tk = [] - for i in xrange(0, KC): - tk.append((ord(key[i * 4]) << 24) | (ord(key[i * 4 + 1]) << 16) | - (ord(key[i * 4 + 2]) << 8) | ord(key[i * 4 + 3])) - - # copy values into round key arrays - t = 0 - j = 0 - while j < KC and t < ROUND_KEY_COUNT: - Ke[t / BC][t % BC] = tk[j] - Kd[ROUNDS - (t / BC)][t % BC] = tk[j] - j += 1 - t += 1 - tt = 0 - rconpointer = 0 - while t < ROUND_KEY_COUNT: - # extrapolate using phi (the round key evolution function) - tt = tk[KC - 1] - tk[0] ^= (S[(tt >> 16) & 0xFF] & 0xFF) << 24 ^ \ - (S[(tt >> 8) & 0xFF] & 0xFF) << 16 ^ \ - (S[ tt & 0xFF] & 0xFF) << 8 ^ \ - (S[(tt >> 24) & 0xFF] & 0xFF) ^ \ - (rcon[rconpointer] & 0xFF) << 24 - rconpointer += 1 - if KC != 8: - for i in xrange(1, KC): - tk[i] ^= tk[i-1] - else: - for i in xrange(1, KC / 2): - tk[i] ^= tk[i-1] - tt = tk[KC / 2 - 1] - tk[KC / 2] ^= (S[ tt & 0xFF] & 0xFF) ^ \ - (S[(tt >> 8) & 0xFF] & 0xFF) << 8 ^ \ - (S[(tt >> 16) & 0xFF] & 0xFF) << 16 ^ \ - (S[(tt >> 24) & 0xFF] & 0xFF) << 24 - for i in xrange(KC / 2 + 1, KC): - tk[i] ^= tk[i-1] - # copy values into round key arrays - j = 0 - while j < KC and t < ROUND_KEY_COUNT: - Ke[t / BC][t % BC] = tk[j] - Kd[ROUNDS - (t / BC)][t % BC] = tk[j] - j += 1 - t += 1 - # inverse MixColumn where needed - for r in xrange(1, ROUNDS): - for j in xrange(BC): - tt = Kd[r][j] - Kd[r][j] = U1[(tt >> 24) & 0xFF] ^ \ - U2[(tt >> 16) & 0xFF] ^ \ - U3[(tt >> 8) & 0xFF] ^ \ - U4[ tt & 0xFF] - self.Ke = Ke - self.Kd = Kd - - def encrypt(self, plaintext): - if len(plaintext) != self.block_size: - raise ValueError('wrong block length, expected ' + str(self.block_size) + ' got ' + str(len(plaintext))) - Ke = self.Ke - - BC = self.block_size / 4 - ROUNDS = len(Ke) - 1 - if BC == 4: - SC = 0 - elif BC == 6: - SC = 1 - else: - SC = 2 - s1 = shifts[SC][1][0] - s2 = shifts[SC][2][0] - s3 = shifts[SC][3][0] - a = [0] * BC - # temporary work array - t = [] - # plaintext to ints + key - for i in xrange(BC): - t.append((ord(plaintext[i * 4 ]) << 24 | - ord(plaintext[i * 4 + 1]) << 16 | - ord(plaintext[i * 4 + 2]) << 8 | - ord(plaintext[i * 4 + 3]) ) ^ Ke[0][i]) - # apply round transforms - for r in xrange(1, ROUNDS): - for i in xrange(BC): - a[i] = (T1[(t[ i ] >> 24) & 0xFF] ^ - T2[(t[(i + s1) % BC] >> 16) & 0xFF] ^ - T3[(t[(i + s2) % BC] >> 8) & 0xFF] ^ - T4[ t[(i + s3) % BC] & 0xFF] ) ^ Ke[r][i] - t = copy.copy(a) - # last round is special - result = [] - for i in xrange(BC): - tt = Ke[ROUNDS][i] - result.append((S[(t[ i ] >> 24) & 0xFF] ^ (tt >> 24)) & 0xFF) - result.append((S[(t[(i + s1) % BC] >> 16) & 0xFF] ^ (tt >> 16)) & 0xFF) - result.append((S[(t[(i + s2) % BC] >> 8) & 0xFF] ^ (tt >> 8)) & 0xFF) - result.append((S[ t[(i + s3) % BC] & 0xFF] ^ tt ) & 0xFF) - return string.join(map(chr, result), '') - - def decrypt(self, ciphertext): - if len(ciphertext) != self.block_size: - raise ValueError('wrong block length, expected ' + str(self.block_size) + ' got ' + str(len(ciphertext))) - Kd = self.Kd - - BC = self.block_size / 4 - ROUNDS = len(Kd) - 1 - if BC == 4: - SC = 0 - elif BC == 6: - SC = 1 - else: - SC = 2 - s1 = shifts[SC][1][1] - s2 = shifts[SC][2][1] - s3 = shifts[SC][3][1] - a = [0] * BC - # temporary work array - t = [0] * BC - # ciphertext to ints + key - for i in xrange(BC): - t[i] = (ord(ciphertext[i * 4 ]) << 24 | - ord(ciphertext[i * 4 + 1]) << 16 | - ord(ciphertext[i * 4 + 2]) << 8 | - ord(ciphertext[i * 4 + 3]) ) ^ Kd[0][i] - # apply round transforms - for r in xrange(1, ROUNDS): - for i in xrange(BC): - a[i] = (T5[(t[ i ] >> 24) & 0xFF] ^ - T6[(t[(i + s1) % BC] >> 16) & 0xFF] ^ - T7[(t[(i + s2) % BC] >> 8) & 0xFF] ^ - T8[ t[(i + s3) % BC] & 0xFF] ) ^ Kd[r][i] - t = copy.copy(a) - # last round is special - result = [] - for i in xrange(BC): - tt = Kd[ROUNDS][i] - result.append((Si[(t[ i ] >> 24) & 0xFF] ^ (tt >> 24)) & 0xFF) - result.append((Si[(t[(i + s1) % BC] >> 16) & 0xFF] ^ (tt >> 16)) & 0xFF) - result.append((Si[(t[(i + s2) % BC] >> 8) & 0xFF] ^ (tt >> 8)) & 0xFF) - result.append((Si[ t[(i + s3) % BC] & 0xFF] ^ tt ) & 0xFF) - return string.join(map(chr, result), '') - -def encrypt(key, block): - return rijndael(key, len(block)).encrypt(block) - -def decrypt(key, block): - return rijndael(key, len(block)).decrypt(block) - -def test(): - def t(kl, bl): - b = 'b' * bl - r = rijndael('a' * kl, bl) - assert r.decrypt(r.encrypt(b)) == b - t(16, 16) - t(16, 24) - t(16, 32) - t(24, 16) - t(24, 24) - t(24, 32) - t(32, 16) - t(32, 24) - t(32, 32) diff --git a/misc/umac/umac.py b/misc/umac/umac.py deleted file mode 100644 index 577dd51b..00000000 --- a/misc/umac/umac.py +++ /dev/null @@ -1,154 +0,0 @@ -# -*- coding: utf-8 -*- - -# Reference implementation from -# http://fastcrypto.org/umac/2004/src/rijndael.py, hacked a bit by -# Nikos Mavrogiannopoulos and Niels Möller to accept command line -# arguments. - -import rijndael -import struct -import fileinput -import sys -import binascii - -if len(sys.argv) < 3: - sys.stderr.write('Usage: umac [taglen] [nonce]\n') - sys.exit(1) - -taglen = int(sys.argv[1]) -nonce = sys.argv[2] - -""" -*** Experimental Python code for verifying test-vectors. -*** Veriosn 0.01 (16 March 2006) - Hereby placed in public domain. -*** Use at your own risk. No warranties, implied or otherwise. - -- Update only works on 1024 byte blocks. Call repeatedly for longer. -- Final only works on final blocks of length 1...8192 bits. -- Hash of empty-string is done via single call to final. -""" - -# Constants -MP64 = 0x01ffffff01ffffffL # Polynomial key masks -MP128 = 0x01ffffff01ffffff01ffffff01ffffffL -M32 = 0xffffffffL # Bit masks -M64 = 0xffffffffffffffffL -P36 = 0xffffffffbL # Prime numbers -P64 = 0xffffffffffffffc5L -P128 = 0xffffffffffffffffffffffffffffff61L -T64 = 0xffffffff00000000L # Polynomial test values -T128 = 0xffffffff000000000000000000000000L - -def nh(key,data,bitlength): - a = 0 - for i in xrange(len(data)//8): - for j in xrange(4): - a += (((data[8*i+j ] + key[8*i+j ]) & M32) * - ((data[8*i+j+4] + key[8*i+j+4]) & M32)) - return (a+bitlength) & M64 # mod 2^^64 - -class umac: - def __init__(self, umacKey, tagLength = 64): - self.taglen = tagLength/8 - self.iters = iters = max(1, min(4,tagLength//32)) - # setup keys - def kdf(kdfCipher, index, numbytes): - ct = [ kdfCipher.encrypt('%s%s%s%s' % ('\x00' * 7, chr(index), '\x00' * 7, chr(i+1))) for i in xrange((numbytes+15)//16) ] - return (''.join(ct))[ : numbytes] - - kdfCipher = rijndael.rijndael(umacKey) - self.pdfCipher = rijndael.rijndael(kdf(kdfCipher,0,len(umacKey))) - # L1Key is a sequence of tuples, each (32-bit * 256) - L1Key = kdf(kdfCipher, 1, 1024 + (iters - 1) * 16) - self.L1Key = [ struct.unpack('>256I', L1Key[16*i:16*i+1024]) for i in xrange(iters) ] - # L2Key is a sequence of tuples, each (64-bit, 128-bit) - L2Key = kdf(kdfCipher, 2, iters * 24) - L2Key = [ struct.unpack('>3Q', L2Key[24*i:24*(i+1)]) for i in xrange(iters) ] - self.L2Key = [ (L2Key[i][0] & MP64, ((L2Key[i][1] << 64) + L2Key[i][2]) & MP128) for i in xrange(iters) ] - # L3Key is a sequence of tuples, each ( [64-bit * 8], 32-bit ) - tmp1 = kdf(kdfCipher, 3, iters * 64) - tmp1 = [ struct.unpack('>8Q', tmp1[64*i:64*(i+1)]) for i in xrange(iters) ] - tmp1 = [ map(lambda x : x % (2**36 - 5), i) for i in tmp1 ] - tmp2 = kdf(kdfCipher, 4, iters * 4) - tmp2 = struct.unpack('>%sI' % str(iters), tmp2) - self.L3Key = zip(tmp1, tmp2) - # Setup empty lists to accumulate L1Hash outputs - self.L1Out = [ list() for i in xrange(iters) ] # A sequence of empty lists - self.L3Out = list() - - def uhashUpdate(self, inString): - data = struct.unpack('<256I', inString) # To big-endian, 256 * 32-bits - for i in xrange(self.iters): - self.L1Out[i].append(nh(self.L1Key[i], data, 8192)) - - def uhashFinal(self, inString, bitlength): - # Pad to 32-byte multiple and unpack to tuple of 32-bit values - if len(inString) == 0: toAppend = 32 - else: toAppend = (32 - (len(inString) % 32)) % 32 - data = '%s%s' % (inString, '\x00' * toAppend) - data = struct.unpack('<%sI' % str(len(data)//4), data) - # Do three-level hash, iter times - for i in xrange(self.iters): - # L1 Hash - self.L1Out[i].append(nh(self.L1Key[i], data, bitlength)) - # L2 Hash - if len(self.L1Out[0]) == 1: - L2Out = self.L1Out[i][0] - else: - loPoly = self.L1Out[i][ : 2**14] - hiPoly = self.L1Out[i][2**14 : ] - for j in xrange(len(loPoly)-1,-1,-1): - if loPoly[j] >= T64: - loPoly[j] = [P64-1, loPoly[j] - 59] - L2Out = reduce(lambda x, y : (x * self.L2Key[i][0] + y) % P64, loPoly, 1) - if (len(hiPoly) > 0): - hiPoly.append(0x8000000000000000L) - if (len(hiPoly) % 2 == 1): - hiPoly.append(0) - hiPoly = [ (hiPoly[j] << 64) + hiPoly[j+1] for j in xrange(0,len(hiPoly),2) ] - hiPoly.insert(0,L2Out) - for j in xrange(len(hiPoly)-1,-1,-1): - if hiPoly[j] >= T128: - hiPoly[j] = [P128-1, hiPoly[j] - 159] - L2Out = reduce(lambda x, y : (x * self.L2Key[i][1] + y) % P128, hiPoly, 1) - #L3 Hash - a,res = L2Out,0; - for j in xrange(7,-1,-1): - res += (a & 0xffff) * self.L3Key[i][0][j] - a >>= 16 - self.L3Out.append(((res % P36) & M32) ^ self.L3Key[i][1]) - - def umacUpdate(self, inString): - self.uhashUpdate(inString) - - def umacFinal(self, inString, bitlength, nonce): - self.uhashFinal(inString, bitlength) - # Generate pad - mask = [None, 3, 1, 0, 0] - nlen = len(nonce) - old = ord(nonce[nlen-1]) - idx = old & mask[self.iters] - pt = '%s%s%s' % (nonce[0:nlen-1], chr(old - idx), '\x00' * (16-nlen)) - pad = struct.unpack('>4I', self.pdfCipher.encrypt(pt)) - result = [ hex(self.L3Out[i] ^ pad[self.iters*idx+i]).rstrip("L").lstrip("0x").zfill(8) for i in xrange(self.iters) ] - self.L1Out = [ list() for i in xrange(self.iters) ] # A sequence of empty lists - self.L3Out = list() - return result - -if nonce[0] == "#": - nonce = binascii.unhexlify(nonce[1:]) - -u = umac('abcdefghijklmnop', taglen) - -last_block = sys.stdin.read(1024) -if len(last_block) == 1024: - while True: - block = sys.stdin.read(1024) - if len(block) == 0: - break; - u.umacUpdate(last_block) - last_block = block; - -tag = u.umacFinal(last_block, 8*len(last_block), nonce) - -print ''.join(tag) diff --git a/misc/umac/vectors.out b/misc/umac/vectors.out deleted file mode 100644 index c1d1e90f..00000000 --- a/misc/umac/vectors.out +++ /dev/null @@ -1,432 +0,0 @@ -nonce: bcdefghi -msg length: 0 -data: -tag32: 113145fb -tag64: 6e155fad26900be1 -tag96: 32fedb100c79ad58f07ff764 -tag128: 32fedb100c79ad58f07ff7643cc60465 - -nonce: bcdefghi -msg length: 3 -data (repeated): a -tag32: 3b91d102 -tag64: 44b5cb542f220104 -tag96: 185e4fe905cba7bd85e4c2dc -tag128: 185e4fe905cba7bd85e4c2dc3d117d8d - -nonce: bcdefghi -msg length: 1024 -data (repeated): a -tag32: 599b350b -tag64: 26bf2f5d60118bd9 -tag96: 7a54abe04af82d60fb298c3c -tag128: 7a54abe04af82d60fb298c3cbd195bcb - -nonce: bcdefghi -msg length: 32768 -data (repeated): a -tag32: 58dcf532 -tag64: 27f8ef643b0d118d -tag96: 7b136bd911e4b734286ef2be -tag128: 7b136bd911e4b734286ef2be501f2c3c - -nonce: bcdefghi -msg length: 1048576 -data (repeated): a -tag32: db6364d1 -tag64: a4477e87e9f55853 -tag96: f8acfa3ac31cfeea047f7b11 -tag128: f8acfa3ac31cfeea047f7b115b03bef5 - -nonce: bcdefghi -msg length: 33554432 -data (repeated): a -tag32: 85ee5cae -tag64: faca46f856e9b45f -tag96: a621c2457c0012e64f3fdae9 -tag128: a621c2457c0012e64f3fdae9e7e1870c - -nonce: bcdefghi -msg length: 3 -data: abc -tag32: abf3a3a0 -tag64: d4d7b9f6bd4fbfcf -tag96: 883c3d4b97a61976ffcf2323 -tag128: 883c3d4b97a61976ffcf232308cba5a5 - -nonce: bcdefghi -msg length: 1500 -data (repeated): abc -tag32: abeb3c8b -tag64: d4cf26ddefd5c01a -tag96: 8824a260c53c66a36c9260a6 -tag128: 8824a260c53c66a36c9260a62cb83aa1 - -nonce: b -msg length: 0 -data (repeated): def -tag32: 3a58486b -tag64: 9e38f67da91a08d9 -tag96: 9e38f67da91a08d9c980f4db -tag128: 9e38f67da91a08d9c980f4db4089c877 - -nonce: bc -msg length: 1 -data (repeated): def -tag32: d86b1512 -tag64: fb0e207971b8e66a -tag96: ef406c2ec70d0222f59e860e -tag128: ef406c2ec70d0222f59e860eabb79ed0 - -nonce: bcd -msg length: 2 -data (repeated): def -tag32: 1ae6e02d -tag64: 1ae6e02d73aa9ab2 -tag96: 1ae6e02d73aa9ab2a27fb89e -tag128: 1ae6e02d73aa9ab2a27fb89e014dc07b - -nonce: bcde -msg length: 3 -data: def -tag32: e8c1eb59 -tag64: c81cf22342e84302 -tag96: 82626d0d575e01038e5e2cc6 -tag128: 82626d0d575e01038e5e2cc6408216f5 - -nonce: bcdef -msg length: 4 -data (repeated): def -tag32: 8950f0d3 -tag64: aba003e7bd673cc3 -tag96: aba003e7bd673cc368ba8513 -tag128: aba003e7bd673cc368ba8513cecf2e7c - -nonce: bcdefg -msg length: 1020 -data (repeated): def -tag32: 7412167c -tag64: f98828a161bb4ae3 -tag96: d8b4811f747d588d7a913360 -tag128: d8b4811f747d588d7a913360960de7cf - -nonce: bcdefgh -msg length: 1021 -data (repeated): def -tag32: 2d54936b -tag64: 2d54936be5bff72d -tag96: 2d54936be5bff72d2e105236 -tag128: 2d54936be5bff72d2e1052361163b474 - -nonce: bcdefghi -msg length: 1022 -data (repeated): def -tag32: 53ca8dd2 -tag64: 2cee9784556387b3 -tag96: 700513397f8a210a98938d3e -tag128: 700513397f8a210a98938d3e7ac3bd88 - -nonce: bcdefghij -msg length: 1023 -data (repeated): def -tag32: 26cc58df -tag64: 24ac4284ca371f42 -tag96: 24ac4284ca371f4280f60bd2 -tag128: 24ac4284ca371f4280f60bd274633d67 - -nonce: bcdefghijk -msg length: 1024 -data (repeated): def -tag32: 3cada45a -tag64: 64c6a0fd14615a76 -tag96: abc223116cedd2db5af365e6 -tag128: abc223116cedd2db5af365e641a97539 - -nonce: bcdefghijkl -msg length: 1025 -data (repeated): def -tag32: 93251e18 -tag64: 93251e18e56bbdc4 -tag96: 93251e18e56bbdc457de556f -tag128: 93251e18e56bbdc457de556f95c59931 - -nonce: bcdefghijklm -msg length: 1026 -data (repeated): def -tag32: 24a4c3ab -tag64: 5d98bd8dfaf16352 -tag96: c1298672e52386753383a15e -tag128: c1298672e52386753383a15ed58c0e42 - -nonce: bcdefghijklmn -msg length: 1027 -data (repeated): def -tag32: e7e98945 -tag64: 5b0557c9fdcf661b -tag96: 5b0557c9fdcf661b1758efc6 -tag128: 5b0557c9fdcf661b1758efc603516ebe - -nonce: bcdefghijklmno -msg length: 2046 -data (repeated): def -tag32: e12ddc9f -tag64: 65e85d47447c2277 -tag96: 16bb5183017826ed47c9995c -tag128: 16bb5183017826ed47c9995c1e5834f3 - -nonce: bcdefghijklmnop -msg length: 2047 -data (repeated): def -tag32: 34d723a6 -tag64: 34d723a6cb1676d3 -tag96: 34d723a6cb1676d3547a5064 -tag128: 34d723a6cb1676d3547a5064dc5b0a37 - -nonce: bcdefghijklmnopq -msg length: 2048 -data (repeated): def -tag32: 21fd8802 -tag64: 3968d5d0af147884 -tag96: 84565620def1e3a614d274e8 -tag128: 84565620def1e3a614d274e87626f215 - -nonce: b -msg length: 2049 -data (repeated): def -tag32: 097e5abd -tag64: ad1ee4ab606061c5 -tag96: ad1ee4ab606061c55e0d2ecf -tag128: ad1ee4ab606061c55e0d2ecfee59940a - -nonce: bc -msg length: 2050 -data (repeated): def -tag32: a03a7fe9 -tag64: 835f4a8242100055 -tag96: 971106d5f4a5e41dce40a917 -tag128: 971106d5f4a5e41dce40a91704cfe1f3 - -nonce: bcd -msg length: 16777212 -data (repeated): def -tag32: 7ef41cf3 -tag64: 7ef41cf351960aaf -tag96: 7ef41cf351960aaf729bb19f -tag128: 7ef41cf351960aaf729bb19fcee7d8c4 - -nonce: bcde -msg length: 16777213 -data (repeated): def -tag32: 8bf81932 -tag64: ab250048807ff640 -tag96: e15b9f6695c9b441de035e9b -tag128: e15b9f6695c9b441de035e9b10b8ac32 - -nonce: bcdef -msg length: 16777214 -data (repeated): def -tag32: ddb2f0ab -tag64: ff42039fcfe1248e -tag96: ff42039fcfe1248e36c19efe -tag128: ff42039fcfe1248e36c19efed14d7140 - -nonce: bcdefg -msg length: 16777215 -data (repeated): def -tag32: e67ad507 -tag64: 6be0ebda623d76df -tag96: 4adc426477fb64b1ce5afd76 -tag128: 4adc426477fb64b1ce5afd76d505f048 - -nonce: bcdefgh -msg length: 16777216 -data (repeated): def -tag32: 42d8562a -tag64: 42d8562a224a9e9a -tag96: 42d8562a224a9e9a75c2f85d -tag128: 42d8562a224a9e9a75c2f85d39462d07 - -nonce: bcdefghi -msg length: 16777217 -data (repeated): def -tag32: 486b138d -tag64: 374f09dbb0b84b88 -tag96: 6ba48d669a51ed3195ebc2aa -tag128: 6ba48d669a51ed3195ebc2aa562ee71b - -nonce: bcdefghij -msg length: 16778239 -data (repeated): def -tag32: 850cb2c5 -tag64: 876ca89ed045777b -tag96: 876ca89ed045777bf7efa793 -tag128: 876ca89ed045777bf7efa7934e1758c2 - -nonce: bcdefghijk -msg length: 16778240 -data (repeated): def -tag32: b9fc4f81 -tag64: e1974b26fb35f2c6 -tag96: 2e93c8ca83b97a6b1a21082e -tag128: 2e93c8ca83b97a6b1a21082e2a4c540d - -nonce: bcdefghijkl -msg length: 16778241 -data (repeated): def -tag32: ffced8f2 -tag64: ffced8f2494d85bf -tag96: ffced8f2494d85bf0cb39408 -tag128: ffced8f2494d85bf0cb39408ddfe0295 - -nonce: bcdefghijklm -msg length: 16778242 -data (repeated): def -tag32: 1c99c5fb -tag64: 65a5bbdda3b85368 -tag96: f9148022bc6ab64f019e9db8 -tag128: f9148022bc6ab64f019e9db83704c17b - -nonce: bcdefghijklmn -msg length: 16778243 -data (repeated): def -tag32: ec304be9 -tag64: 50dc9565fbfc4884 -tag96: 50dc9565fbfc48844a4be344 -tag128: 50dc9565fbfc48844a4be34403804605 - -nonce: bcdefghijklmno -msg length: 16778244 -data (repeated): def -tag32: 8034e26f -tag64: 04f163b7c2d5d849 -tag96: 77a26f7387d1dcd39378a322 -tag128: 77a26f7387d1dcd39378a3220652cff7 - -nonce: #00000000000000000000000000000000 -msg length: 4 -data: zero -tag32: a0e94011 -tag64: a0e940111c9c2cd5 -tag96: a0e940111c9c2cd5fa59090e -tag128: a0e940111c9c2cd5fa59090e3ac2061f - -nonce: #00000000000000000000000000000001 -msg length: 4 -data: zero -tag32: 8c6fea51 -tag64: 6d8971434be8ee41 -tag96: cbbf18b799fd0f4afb9216e5 -tag128: cbbf18b799fd0f4afb9216e52a89f247 - -nonce: #00000000000000000000000000000002 -msg length: 4 -data: zero -tag32: 6d897143 -tag64: c9c9aef87e2be502 -tag96: c9c9aef87e2be50237716af8 -tag128: c9c9aef87e2be50237716af8e24f8959 - -nonce: #00000000000000000000000000000003 -msg length: 4 -data: zero -tag32: db1b28c5 -tag64: a0a112b593656107 -tag96: d6e96ef461f54d1c85aa66cb -tag128: d6e96ef461f54d1c85aa66cbd76ca336 - -nonce: #00000000000000000000000000000004 -msg length: 4 -data: zero -tag32: a75e23b7 -tag64: a75e23b7d419e03a -tag96: a75e23b7d419e03a02d55ebf -tag128: a75e23b7d419e03a02d55ebf1ba62824 - -nonce: #00000000000000000000000000000005 -msg length: 4 -data: zero -tag32: 44ea26be -tag64: 950526f26a8cc07a -tag96: 2e63031d182a59b84f148d9a -tag128: 2e63031d182a59b84f148d9a91de70a3 - -nonce: a -msg length: 7 -data: nonce-a -tag32: 81b4ac24 -tag64: b7e8aad0da6e7f99 -tag96: d7604bffb5e368da5fe564da -tag128: d7604bffb5e368da5fe564da0068d2cc - -nonce: b -msg length: 7 -data: nonce-a -tag32: b7e8aad0 -tag64: 138814c6a03bdadf -tag96: 138814c6a03bdadff7f1666e -tag128: 138814c6a03bdadff7f1666e1bd881aa - -nonce: c -msg length: 7 -data: nonce-a -tag32: f70246fe -tag64: fb77dd1cd4c7074f -tag96: 86a016d9e67957c8ab5ebb78 -tag128: 86a016d9e67957c8ab5ebb78a673e4e9 - -nonce: d -msg length: 7 -data: nonce-a -tag32: 0595f0bf -tag64: 0595f0bf8585c7e2 -tag96: 0595f0bf8585c7e28dfab005 -tag128: 0595f0bf8585c7e28dfab00598d4e612 - -nonce: e -msg length: 7 -data: nonce-a -tag32: a8e9fe85 -tag64: 817c0b7757cb60f7 -tag96: 3266ec16a9d85b4f0dc74ec8 -tag128: 3266ec16a9d85b4f0dc74ec8272238a9 - -nonce: #beafcafe -msg length: 15 -data: nonce-beaf-cafe -tag32: f19d9dc1 -tag64: 9e878413aa079032 -tag96: 9e878413aa0790329604f3b6 -tag128: 9e878413aa0790329604f3b6ae980e58 - -nonce: #beafcaff -msg length: 15 -data: nonce-beaf-cafe -tag32: 4604a56a -tag64: 9cfd7af0bb107748 -tag96: f2b2dd5dab08bb3bc5e9a83e -tag128: f2b2dd5dab08bb3bc5e9a83e1b4ab2e7 - -nonce: #beafcb00 -msg length: 15 -data: nonce-beaf-cafe -tag32: 4ba9420e -tag64: 4ba9420e55b6ba13 -tag96: 4ba9420e55b6ba137d03443f -tag128: 4ba9420e55b6ba137d03443f6ee01734 - -nonce: #beafcb01 -msg length: 15 -data: nonce-beaf-cafe -tag32: da86ff71 -tag64: 77facd797b686e24 -tag96: 2721ca2e1bcda53a54ae65e0 -tag128: 2721ca2e1bcda53a54ae65e0da139c0d - -nonce: #beafcb02 -msg length: 15 -data: nonce-beaf-cafe -tag32: 77facd79 -tag64: 9000c0de4f5f7236 -tag96: 9000c0de4f5f7236b81ae1a5 -tag128: 9000c0de4f5f7236b81ae1a52e78a821 - |
