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

Method GetRandomBytes

libcppcryptfs/crypt/randombytes.cpp:45–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43}
44
45bool RandomBytes::GetRandomBytes(unsigned char *buf, DWORD len)
46{
47 if (len > RANDOM_POOL_SIZE) {
48 return get_sys_random_bytes(buf, len);
49 }
50
51 bool bret = true;
52
53 lock();
54
55 if (m_bufpos + len < RANDOM_POOL_SIZE) {
56 memcpy(buf, m_randbuf + m_bufpos, len);
57 m_bufpos += len;
58 } else {
59 DWORD bytes_copied = 0;
60 if (m_bufpos < RANDOM_POOL_SIZE) {
61 memcpy(buf, m_randbuf + m_bufpos, RANDOM_POOL_SIZE - m_bufpos);
62 bytes_copied += RANDOM_POOL_SIZE - m_bufpos;
63 m_bufpos += bytes_copied;
64 }
65 if (get_sys_random_bytes(m_randbuf, RANDOM_POOL_SIZE)) {
66 m_bufpos = 0;
67 memcpy(buf + bytes_copied, m_randbuf, len - bytes_copied);
68 m_bufpos += len - bytes_copied;
69 } else {
70 bret = false;
71 }
72 }
73
74 unlock();
75
76 return bret;
77}

Callers 1

get_random_bytesFunction · 0.80

Calls 1

get_sys_random_bytesFunction · 0.85

Tested by

no test coverage detected