MCPcopy Create free account
hub / github.com/c3d/tao3D / UncheckedSetKey

Method UncheckedSetKey

libcryptopp/cryptopp/vmac.cpp:36–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34#endif
35
36void VMAC_Base::UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs &params)
37{
38 int digestLength = params.GetIntValueWithDefault(Name::DigestSize(), DefaultDigestSize());
39 if (digestLength != 8 && digestLength != 16)
40 throw InvalidArgument("VMAC: DigestSize must be 8 or 16");
41 m_is128 = digestLength == 16;
42
43 m_L1KeyLength = params.GetIntValueWithDefault(Name::L1KeyLength(), 128);
44 if (m_L1KeyLength <= 0 || m_L1KeyLength % 128 != 0)
45 throw InvalidArgument("VMAC: L1KeyLength must be a positive multiple of 128");
46
47 AllocateBlocks();
48
49 BlockCipher &cipher = AccessCipher();
50 cipher.SetKey(userKey, keylength, params);
51 unsigned int blockSize = cipher.BlockSize();
52 unsigned int blockSizeInWords = blockSize / sizeof(word64);
53 SecBlock<word64> out(blockSizeInWords);
54 SecByteBlock in;
55 in.CleanNew(blockSize);
56 size_t i;
57
58 /* Fill nh key */
59 in[0] = 0x80;
60 cipher.AdvancedProcessBlocks(in, NULL, (byte *)m_nhKey(), m_nhKeySize()*sizeof(word64), cipher.BT_InBlockIsCounter);
61 ConditionalByteReverse<word64>(BIG_ENDIAN_ORDER, m_nhKey(), m_nhKey(), m_nhKeySize()*sizeof(word64));
62
63 /* Fill poly key */
64 in[0] = 0xC0;
65 in[15] = 0;
66 for (i = 0; i <= (size_t)m_is128; i++)
67 {
68 cipher.ProcessBlock(in, out.BytePtr());
69 m_polyState()[i*4+2] = GetWord<word64>(true, BIG_ENDIAN_ORDER, out.BytePtr()) & mpoly;
70 m_polyState()[i*4+3] = GetWord<word64>(true, BIG_ENDIAN_ORDER, out.BytePtr()+8) & mpoly;
71 in[15]++;
72 }
73
74 /* Fill ip key */
75 in[0] = 0xE0;
76 in[15] = 0;
77 word64 *l3Key = m_l3Key();
78 for (i = 0; i <= (size_t)m_is128; i++)
79 do
80 {
81 cipher.ProcessBlock(in, out.BytePtr());
82 l3Key[i*2+0] = GetWord<word64>(true, BIG_ENDIAN_ORDER, out.BytePtr());
83 l3Key[i*2+1] = GetWord<word64>(true, BIG_ENDIAN_ORDER, out.BytePtr()+8);
84 in[15]++;
85 } while ((l3Key[i*2+0] >= p64) || (l3Key[i*2+1] >= p64));
86
87 m_padCached = false;
88 size_t nonceLength;
89 const byte *nonce = GetIVAndThrowIfInvalid(params, nonceLength);
90 Resynchronize(nonce, (int)nonceLength);
91}
92
93void VMAC_Base::GetNextIV(RandomNumberGenerator &rng, byte *IV)

Callers

nothing calls this directly

Calls 7

CleanNewMethod · 0.80
AdvancedProcessBlocksMethod · 0.80
BytePtrMethod · 0.80
DigestSizeFunction · 0.70
ResynchronizeFunction · 0.70
SetKeyMethod · 0.45
BlockSizeMethod · 0.45

Tested by

no test coverage detected