本文整理汇总了C++中secure_vector::data方法的典型用法代码示例。如果您正苦于以下问题:C++ secure_vector::data方法的具体用法?C++ secure_vector::data怎么用?C++ secure_vector::data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类secure_vector
的用法示例。
在下文中一共展示了secure_vector::data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Encoding_Error
bool EMSA1::verify(const secure_vector<uint8_t>& input,
const secure_vector<uint8_t>& raw,
size_t key_bits)
{
try {
if(raw.size() != m_hash->output_length())
throw Encoding_Error("EMSA1::encoding_of: Invalid size for input");
// Call emsa1_encoding to handle any required bit shifting
const secure_vector<uint8_t> our_coding = emsa1_encoding(raw, key_bits);
if(our_coding.size() < input.size())
return false;
const size_t offset = our_coding.size() - input.size(); // must be >= 0 per check above
// If our encoding is longer, all the bytes in it must be zero
for(size_t i = 0; i != offset; ++i)
if(our_coding[i] != 0)
return false;
return same_mem(input.data(), &our_coding[offset], input.size());
}
catch(Invalid_Argument)
{
return false;
}
}
示例2:
Ed25519_PrivateKey::Ed25519_PrivateKey(RandomNumberGenerator& rng)
{
const secure_vector<uint8_t> seed = rng.random_vec(32);
m_public.resize(32);
m_private.resize(64);
ed25519_gen_keypair(m_public.data(), m_private.data(), seed.data());
}
示例3: mceliece_decrypt
void mceliece_decrypt(secure_vector<byte>& plaintext_out,
secure_vector<byte>& error_mask_out,
const secure_vector<byte>& ciphertext,
const McEliece_PrivateKey& key)
{
mceliece_decrypt(plaintext_out, error_mask_out, ciphertext.data(), ciphertext.size(), key);
}
示例4: mul_by
void Montgomery_Params::mul_by(BigInt& x,
const secure_vector<word>& y,
secure_vector<word>& ws) const
{
const size_t output_size = 2*m_p_words + 2;
if(ws.size() < 2*output_size)
ws.resize(2*output_size);
word* z_data = &ws[0];
word* ws_data = &ws[output_size];
BOTAN_DEBUG_ASSERT(x.sig_words() <= m_p_words);
bigint_mul(z_data, output_size,
x.data(), x.size(), std::min(m_p_words, x.size()),
y.data(), y.size(), std::min(m_p_words, y.size()),
ws_data, output_size);
bigint_monty_redc(z_data,
m_p.data(), m_p_words, m_p_dash,
ws_data, output_size);
if(x.size() < output_size)
x.grow_to(output_size);
copy_mem(x.mutable_data(), z_data, output_size);
}
示例5: if
//static
void SHA_3::expand(size_t bitrate,
secure_vector<uint64_t>& S,
uint8_t output[], size_t output_length)
{
BOTAN_ARG_CHECK(bitrate % 8 == 0);
size_t Si = 0;
for(size_t i = 0; i != output_length; ++i)
{
if(i > 0)
{
if(i % (bitrate / 8) == 0)
{
SHA_3::permute(S.data());
Si = 0;
}
else if(i % 8 == 0)
{
Si += 1;
}
}
output[i] = get_byte(7 - (i % 8), S[Si]);
}
}
示例6: finish
void EAX_Decryption::finish(secure_vector<byte>& buffer, size_t offset)
{
BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane");
const size_t sz = buffer.size() - offset;
byte* buf = buffer.data() + offset;
BOTAN_ASSERT(sz >= tag_size(), "Have the tag as part of final input");
const size_t remaining = sz - tag_size();
if(remaining)
{
m_cmac->update(buf, remaining);
m_ctr->cipher(buf, buf, remaining);
}
const byte* included_tag = &buf[remaining];
secure_vector<byte> mac = m_cmac->final();
mac ^= m_nonce_mac;
mac ^= m_ad_mac;
if(!same_mem(mac.data(), included_tag, tag_size()))
throw Integrity_Failure("EAX tag check failed");
buffer.resize(offset + remaining);
}
示例7: process
void Stream_Decompression::process(secure_vector<byte>& buf, size_t offset, u32bit flags)
{
BOTAN_ASSERT(m_stream, "Initialized");
BOTAN_ASSERT(buf.size() >= offset, "Offset is sane");
if(m_buffer.size() < buf.size() + offset)
m_buffer.resize(buf.size() + offset);
m_stream->next_in(buf.data() + offset, buf.size() - offset);
m_stream->next_out(m_buffer.data() + offset, m_buffer.size() - offset);
while(true)
{
const bool stream_end = m_stream->run(flags);
if(stream_end)
{
if(m_stream->avail_in() == 0) // all data consumed?
{
m_buffer.resize(m_buffer.size() - m_stream->avail_out());
clear();
break;
}
// More data follows: try to process as a following stream
const size_t read = (buf.size() - offset) - m_stream->avail_in();
start();
m_stream->next_in(buf.data() + offset + read, buf.size() - offset - read);
}
if(m_stream->avail_out() == 0)
{
const size_t added = 8 + m_buffer.size();
m_buffer.resize(m_buffer.size() + added);
m_stream->next_out(m_buffer.data() + m_buffer.size() - added, added);
}
else if(m_stream->avail_in() == 0)
{
m_buffer.resize(m_buffer.size() - m_stream->avail_out());
break;
}
}
copy_mem(m_buffer.data(), buf.data(), offset);
buf.swap(m_buffer);
}
示例8: update
void EAX_Decryption::update(secure_vector<byte>& buffer, size_t offset)
{
BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane");
const size_t sz = buffer.size() - offset;
byte* buf = buffer.data() + offset;
m_cmac->update(buf, sz);
m_ctr->cipher(buf, buf, sz);
}
示例9: generate_hotp
uint32_t HOTP::generate_hotp(uint64_t counter)
{
m_mac->update_be(counter);
const secure_vector<uint8_t> mac = m_mac->final();
const size_t offset = mac[mac.size()-1] & 0x0F;
const uint32_t code = load_be<uint32_t>(mac.data() + offset, 0) & 0x7FFFFFFF;
return code % m_digit_mod;
}
示例10: update
void CCM_Mode::update(secure_vector<byte>& buffer, size_t offset)
{
BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane");
const size_t sz = buffer.size() - offset;
byte* buf = buffer.data() + offset;
m_msg_buf.insert(m_msg_buf.end(), buf, buf + sz);
buffer.resize(offset); // truncate msg
}
示例11: finish
void CCM_Decryption::finish(secure_vector<byte>& buffer, size_t offset)
{
BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane");
buffer.insert(buffer.begin() + offset, msg_buf().begin(), msg_buf().end());
const size_t sz = buffer.size() - offset;
byte* buf = buffer.data() + offset;
BOTAN_ASSERT(sz >= tag_size(), "We have the tag");
const secure_vector<byte>& ad = ad_buf();
BOTAN_ASSERT(ad.size() % BS == 0, "AD is block size multiple");
const BlockCipher& E = cipher();
secure_vector<byte> T(BS);
E.encrypt(format_b0(sz - tag_size()), T);
for(size_t i = 0; i != ad.size(); i += BS)
{
xor_buf(T.data(), &ad[i], BS);
E.encrypt(T);
}
secure_vector<byte> C = format_c0();
secure_vector<byte> S0(BS);
E.encrypt(C, S0);
inc(C);
secure_vector<byte> X(BS);
const byte* buf_end = &buf[sz - tag_size()];
while(buf != buf_end)
{
const size_t to_proc = std::min<size_t>(BS, buf_end - buf);
E.encrypt(C, X);
xor_buf(buf, X.data(), to_proc);
inc(C);
xor_buf(T.data(), buf, to_proc);
E.encrypt(T);
buf += to_proc;
}
T ^= S0;
if(!same_mem(T.data(), buf_end, tag_size()))
throw Integrity_Failure("CCM tag check failed");
buffer.resize(buffer.size() - tag_size());
}
示例12:
//static
void SHA_3::finish(size_t bitrate,
secure_vector<uint64_t>& S, size_t S_pos,
uint8_t init_pad, uint8_t fini_pad)
{
BOTAN_ARG_CHECK(bitrate % 64 == 0, "SHA-3 bitrate must be multiple of 64");
S[S_pos / 8] ^= static_cast<uint64_t>(init_pad) << (8 * (S_pos % 8));
S[(bitrate / 64) - 1] ^= static_cast<uint64_t>(fini_pad) << 56;
SHA_3::permute(S.data());
}
示例13: sqr
BigInt Montgomery_Params::sqr(const BigInt& x, secure_vector<word>& ws) const
{
const size_t output_size = 2*m_p_words + 2;
if(ws.size() < output_size)
ws.resize(output_size);
BigInt z(BigInt::Positive, output_size);
BOTAN_DEBUG_ASSERT(x.sig_words() <= m_p_words);
bigint_sqr(z.mutable_data(), z.size(),
x.data(), x.size(), std::min(m_p_words, x.size()),
ws.data(), ws.size());
bigint_monty_redc(z.mutable_data(),
m_p.data(), m_p_words, m_p_dash,
ws.data(), ws.size());
return z;
}
示例14:
secure_vector<byte>
PK_Decryptor::decrypt_or_random(const byte in[],
size_t length,
size_t expected_pt_len,
RandomNumberGenerator& rng,
const byte required_content_bytes[],
const byte required_content_offsets[],
size_t required_contents_length) const
{
const secure_vector<byte> fake_pms = rng.random_vec(expected_pt_len);
//CT::poison(in, length);
byte valid_mask = 0;
secure_vector<byte> decoded = do_decrypt(valid_mask, in, length);
valid_mask &= CT::is_equal(decoded.size(), expected_pt_len);
decoded.resize(expected_pt_len);
for(size_t i = 0; i != required_contents_length; ++i)
{
/*
These values are chosen by the application and for TLS are constants,
so this early failure via assert is fine since we know 0,1 < 48
If there is a protocol that has content checks on the key where
the expected offsets are controllable by the attacker this could
still leak.
Alternately could always reduce the offset modulo the length?
*/
const byte exp = required_content_bytes[i];
const byte off = required_content_offsets[i];
BOTAN_ASSERT(off < expected_pt_len, "Offset in range of plaintext");
valid_mask &= CT::is_equal(decoded[off], exp);
}
CT::conditional_copy_mem(valid_mask,
/*output*/decoded.data(),
/*from0*/decoded.data(),
/*from1*/fake_pms.data(),
expected_pt_len);
//CT::unpoison(in, length);
//CT::unpoison(decoded.data(), decoded.size());
return decoded;
}
示例15: aes
secure_vector<uint8_t> rfc3394_keywrap(const secure_vector<uint8_t>& key,
const SymmetricKey& kek)
{
BOTAN_ARG_CHECK(kek.size() == 16 || kek.size() == 24 || kek.size() == 32,
"Invalid KEK length for NIST key wrap");
const std::string cipher_name = "AES-" + std::to_string(8*kek.size());
std::unique_ptr<BlockCipher> aes(BlockCipher::create_or_throw(cipher_name));
aes->set_key(kek);
std::vector<uint8_t> wrapped = nist_key_wrap(key.data(), key.size(), *aes);
return secure_vector<uint8_t>(wrapped.begin(), wrapped.end());
}