MCPcopy Create free account
hub / github.com/bailey27/cppcryptfs / SetKey

Method SetKey

libcppcryptfs/crypt/siv.cpp:47–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45}
46
47bool SivContext::SetKey(const unsigned char *key, int keylen, bool hkdf, CryptConfig *pConfig)
48{
49 if (keylen != 32)
50 return false;
51
52 if (!pConfig)
53 throw std::exception("SivContext::SetKey where is my config?");
54
55 if (!m_pKeys)
56 m_pKeys = new LockZeroBuffer<AES_KEY>(4, true);
57
58 pConfig->m_keybuf_manager.RegisterBuf(m_pKeys);
59
60 LockZeroBuffer<BYTE> key64(64, true);
61
62 if (hkdf) {
63 if (!hkdfDerive(key, keylen, key64.m_buf, key64.m_len, hkdfInfoSIVContent))
64 return false;
65 } else {
66 if (!sha512(key, 32, key64.m_buf))
67 return false;
68 }
69
70 AES::initialize_keys(key64.m_buf, 256, &m_pKeys->m_buf[SIV_KEY_ENCRYPT_LOW_INDEX],
71 &m_pKeys->m_buf[SIV_KEY_DECRYPT_LOW_INDEX]);
72
73 AES::initialize_keys(key64.m_buf + 32 , 256, &m_pKeys->m_buf[SIV_KEY_ENCRYPT_HIGH_INDEX],
74 &m_pKeys->m_buf[SIV_KEY_DECRYPT_HIGH_INDEX]);
75
76 return true;
77}

Callers 1

mount_crypt_fsFunction · 0.80

Calls 3

hkdfDeriveFunction · 0.85
sha512Function · 0.85
RegisterBufMethod · 0.45

Tested by

no test coverage detected