MCPcopy Create free account
hub / github.com/LUX-Core/lux / UncheckedSetKey

Method UncheckedSetKey

src/cryptopp/vmac.cpp:55–112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53#endif
54
55void VMAC_Base::UncheckedSetKey(const byte *userKey, unsigned int keylength, const NameValuePairs &params)
56{
57 int digestLength = params.GetIntValueWithDefault(Name::DigestSize(), DefaultDigestSize());
58 if (digestLength != 8 && digestLength != 16)
59 throw InvalidArgument("VMAC: DigestSize must be 8 or 16");
60 m_is128 = digestLength == 16;
61
62 m_L1KeyLength = params.GetIntValueWithDefault(Name::L1KeyLength(), 128);
63 if (m_L1KeyLength <= 0 || m_L1KeyLength % 128 != 0)
64 throw InvalidArgument("VMAC: L1KeyLength must be a positive multiple of 128");
65
66 AllocateBlocks();
67
68 BlockCipher &cipher = AccessCipher();
69 cipher.SetKey(userKey, keylength, params);
70 const unsigned int blockSize = cipher.BlockSize();
71 const unsigned int blockSizeInWords = blockSize / sizeof(word64);
72 SecBlock<word64> out(blockSizeInWords);
73 SecByteBlock in;
74 in.CleanNew(blockSize);
75 size_t i;
76
77 /* Fill nh key */
78 in[0] = 0x80;
79 cipher.AdvancedProcessBlocks(in, NULL, (byte *)m_nhKey(), m_nhKeySize()*sizeof(word64), cipher.BT_InBlockIsCounter);
80 ConditionalByteReverse<word64>(BIG_ENDIAN_ORDER, m_nhKey(), m_nhKey(), m_nhKeySize()*sizeof(word64));
81
82 /* Fill poly key */
83 in[0] = 0xC0;
84 in[15] = 0;
85 for (i = 0; i <= (size_t)m_is128; i++)
86 {
87 cipher.ProcessBlock(in, out.BytePtr());
88 m_polyState()[i*4+2] = GetWord<word64>(true, BIG_ENDIAN_ORDER, out.BytePtr()) & mpoly;
89 m_polyState()[i*4+3] = GetWord<word64>(true, BIG_ENDIAN_ORDER, out.BytePtr()+8) & mpoly;
90 in[15]++;
91 }
92
93 /* Fill ip key */
94 in[0] = 0xE0;
95 in[15] = 0;
96 word64 *l3Key = m_l3Key();
97 CRYPTOPP_ASSERT(IsAlignedOn(l3Key,GetAlignmentOf<word64>()));
98
99 for (i = 0; i <= (size_t)m_is128; i++)
100 do
101 {
102 cipher.ProcessBlock(in, out.BytePtr());
103 l3Key[i*2+0] = GetWord<word64>(true, BIG_ENDIAN_ORDER, out.BytePtr());
104 l3Key[i*2+1] = GetWord<word64>(true, BIG_ENDIAN_ORDER, out.BytePtr()+8);
105 in[15]++;
106 } while ((l3Key[i*2+0] >= p64) || (l3Key[i*2+1] >= p64));
107
108 m_padCached = false;
109 size_t nonceLength;
110 const byte *nonce = GetIVAndThrowIfInvalid(params, nonceLength);
111 Resynchronize(nonce, (int)nonceLength);
112}

Callers

nothing calls this directly

Calls 9

IsAlignedOnFunction · 0.85
CleanNewMethod · 0.80
AdvancedProcessBlocksMethod · 0.80
ProcessBlockMethod · 0.80
BytePtrMethod · 0.80
DigestSizeFunction · 0.70
ResynchronizeFunction · 0.70
SetKeyMethod · 0.45
BlockSizeMethod · 0.45

Tested by

no test coverage detected