本文整理汇总了C++中MD5Final函数的典型用法代码示例。如果您正苦于以下问题:C++ MD5Final函数的具体用法?C++ MD5Final怎么用?C++ MD5Final使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MD5Final函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: smbfs_getino
/*
* Lack of inode numbers leads us to the problem of generating them.
* Partially this problem can be solved by having a dir/file cache
* with inode numbers generated from the incremented by one counter.
* However this way will require too much kernel memory, gives all
* sorts of locking and consistency problems, not to mentinon counter overflows.
* So, I'm decided to use a hash function to generate pseudo random (and unique)
* inode numbers.
*/
static long
smbfs_getino(struct smbnode *dnp, const char *name, int nmlen)
{
#ifdef USE_MD5_HASH
MD5_CTX md5;
u_int32_t state[4];
long ino;
int i;
MD5Init(&md5);
MD5Update(&md5, name, nmlen);
MD5Final((u_char *)state, &md5);
for (i = 0, ino = 0; i < 4; i++)
ino += state[i];
return dnp->n_ino + ino;
#endif
u_int32_t ino;
ino = dnp->n_ino + hash32_strn(name, nmlen, HASH32_STR_INIT);
if (ino <= 2)
ino += 3;
return ino;
}
示例2: search
// Search all strings of length 'len' for one that hashes to 'hash'.
void *
search(void *args)
{
search_args *a = args;
assert(a->lo < a->hi);
assert(a->hi <= a->len);
//cprintf("searching strings starting from '%s'\n", a->str);
do {
unsigned char h[16];
//cprintf("checking '%s'\n", a->str);
MD5_CTX ctx;
MD5Init(&ctx);
MD5Update(&ctx, a->str, a->len);
MD5Final(h, &ctx);
if (memcmp(h, a->hash, 16) == 0) {
strcpy(out, (char*)a->str);
found = 1;
return NULL;
}
} while (!incstr(a->str, a->lo, a->hi));
return NULL;
}
示例3: set_md5sum
static void set_md5sum(HIO_HANDLE *f, unsigned char *digest)
{
unsigned char buf[BUFLEN];
MD5_CTX ctx;
int bytes_read;
struct stat st;
if (hio_stat(f, &st) < 0)
return;
if (st.st_size <= 0) {
memset(digest, 0, 16);
return;
}
hio_seek(f, 0, SEEK_SET);
MD5Init(&ctx);
while ((bytes_read = hio_read(buf, 1, BUFLEN, f)) > 0) {
MD5Update(&ctx, buf, bytes_read);
}
MD5Final(digest, &ctx);
}
示例4: encode_wkssvc_join_password_buffer
void encode_wkssvc_join_password_buffer(TALLOC_CTX *mem_ctx,
const char *pwd,
DATA_BLOB *session_key,
struct wkssvc_PasswordBuffer **pwd_buf)
{
uint8_t buffer[516];
MD5_CTX ctx;
struct wkssvc_PasswordBuffer *my_pwd_buf = NULL;
DATA_BLOB confounded_session_key;
int confounder_len = 8;
uint8_t confounder[8];
my_pwd_buf = talloc_zero(mem_ctx, struct wkssvc_PasswordBuffer);
if (!my_pwd_buf) {
return;
}
confounded_session_key = data_blob_talloc(mem_ctx, NULL, 16);
encode_pw_buffer(buffer, pwd, STR_UNICODE);
generate_random_buffer((uint8_t *)confounder, confounder_len);
MD5Init(&ctx);
MD5Update(&ctx, session_key->data, session_key->length);
MD5Update(&ctx, confounder, confounder_len);
MD5Final(confounded_session_key.data, &ctx);
arcfour_crypt_blob(buffer, 516, &confounded_session_key);
memcpy(&my_pwd_buf->data[0], confounder, confounder_len);
memcpy(&my_pwd_buf->data[8], buffer, 516);
data_blob_free(&confounded_session_key);
*pwd_buf = my_pwd_buf;
}
示例5: MD5String
std::string MD5String(int stringCount, ...)
{
MD5_CTX context;
unsigned char digest[16];
va_list arguments;
// Prepare hash.
MD5Init(&context);
// Hash all strings.
va_start(arguments, stringCount);
for (int x = 0; x < stringCount; x++)
{
auto nextString = va_arg(arguments, std::string);
const char* stringContent = nextString.c_str();
unsigned int len = strlen(stringContent);
MD5Update(&context, (unsigned char *)stringContent, len);
}
va_end(arguments);
// Finalize hash.
MD5Final(digest, &context);
// Convert from binary to hex.
char digestStringBuffer[64];
unsigned int i;
unsigned int bytes = 0;
for (i = 0; i < 16; i++)
{
bytes += sprintf_s(digestStringBuffer + bytes, 64 - bytes, "%02x", digest[i]);
}
// Convert to string.
return std::string(digestStringBuffer);
}
示例6: Hashit
static void Hashit(TCHAR *filename)
{
FILE *FileToHash;
MD5_CTX MDContext;
int bytes;
int i;
unsigned char data[1024];
unsigned char hash[32];
unsigned char tmphash[10];
errno_t err;
err = _tfopen_s(&FileToHash, filename, TEXT("rb"));
if((err != 0) || (FileToHash == NULL))
{
return;
}
MD5Init(&MDContext);
while((bytes = fread(data, 1, 1024, FileToHash)) != 0)
{
MD5Update(&MDContext, data, bytes);
}
fclose(FileToHash);
MD5Final(&MDContext);
sprintf(hash, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
MDContext.digest[0], MDContext.digest[1], MDContext.digest[2], MDContext.digest[3],
MDContext.digest[4], MDContext.digest[5], MDContext.digest[6], MDContext.digest[7],
MDContext.digest[8], MDContext.digest[9], MDContext.digest[10], MDContext.digest[11],
MDContext.digest[12], MDContext.digest[13], MDContext.digest[14], MDContext.digest[15]);
fprintf(fp,"%s*", hash);
_ftprintf(fp, "%s\n", filename);
}
示例7: auth8651bGeneralApiTestItem
static int32 auth8651bGeneralApiTestItem(uint32 mode, uint8 * input, uint32 pktLen, uint8 * key, uint32 keyLen) {
MD5_CTX md5Context;
SHA1_CTX sha1Context;
if(rtl8651b_authEngine(mode, input, pktLen, key, keyLen, asicDigest) == FAILED)
return FAILED;//When authentication engine cannot calculate digest, the testing is surely failed
authSim(mode, input, pktLen, key, keyLen, simDigest);
if(memcmp(simDigest, asicDigest, (mode&0x1)? RTL8651B_SHA1_DIGEST_LENGTH: RTL8651B_MD5_DIGEST_LENGTH) != 0) {
switch(mode) {
case HASH_MD5:
MD5Init(&md5Context);
MD5Update(&md5Context, input, pktLen);
MD5Final(swDigest, &md5Context);
break;
case HASH_SHA1:
SHA1Init(&sha1Context);
SHA1Update(&sha1Context, input, pktLen);
SHA1Final(swDigest, &sha1Context);
break;
case HMAC_MD5:
HMACMD5(input, pktLen, key, keyLen, swDigest);
break;
case HMAC_SHA1:
HMACSHA1(input, pktLen, key, keyLen, swDigest);
break;
}
if(memcmp(simDigest, swDigest, (mode&0x1)? RTL8651B_SHA1_DIGEST_LENGTH: RTL8651B_MD5_DIGEST_LENGTH) != 0)
displayDigestMismatch(authModeString[mode], input, pktLen, key, keyLen, "SW", swDigest, "SIM", simDigest, (mode&0x1)? RTL8651B_SHA1_DIGEST_LENGTH: RTL8651B_MD5_DIGEST_LENGTH);
else {
displayDigestMismatch(authModeString[mode], input, pktLen, key, keyLen, "SIM", simDigest, "ASIC", asicDigest, (mode&0x1)? RTL8651B_SHA1_DIGEST_LENGTH: RTL8651B_MD5_DIGEST_LENGTH);
triggerGpio();
//rtl8651b_authEngineData(mode, input, pktLen, key, keyLen);
}
return FAILED;
}
return SUCCESS;
}
示例8: MD5Init
void ASF_LegacyManager::ComputeDigest()
{
MD5_CTX context;
MD5_Digest digest;
char buffer[40];
MD5Init ( &context );
digestStr.clear();
digestStr.reserve ( 160 );
for ( int type=0; type < fieldLast; ++type ) {
if (fields[type].size ( ) > 0 ) {
snprintf ( buffer, sizeof(buffer), "%d,", type );
digestStr.append ( buffer );
MD5Update ( &context, (XMP_Uns8*)fields[type].data(), fields[type].size() );
}
}
if( digestStr.size() > 0 ) digestStr[digestStr.size()-1] = ';';
MD5Final ( digest, &context );
size_t in, out;
for ( in = 0, out = 0; in < 16; in += 1, out += 2 ) {
XMP_Uns8 byte = digest[in];
buffer[out] = ReconcileUtils::kHexDigits [ byte >> 4 ];
buffer[out+1] = ReconcileUtils::kHexDigits [ byte & 0xF ];
}
buffer[32] = 0;
digestStr.append ( buffer );
digestComputed = true;
}
示例9: OS_MD5_File
int OS_MD5_File(char * fname, char * output)
{
FILE *fp;
MD5_CTX ctx;
unsigned char buf[1024 +1];
unsigned char digest[16];
int n;
memset(output,0, 33);
buf[1024] = '\0';
fp = fopen(fname,"rb");
if(!fp)
{
return(-1);
}
MD5Init(&ctx);
while((n = fread(buf, 1, sizeof(buf) -1, fp)) > 0)
{
buf[n] = '\0';
MD5Update(&ctx,buf,n);
}
MD5Final(digest, &ctx);
for(n = 0;n < 16; n++)
{
snprintf(output, 3, "%02x", digest[n]);
output+=2;
}
/* Closing it */
fclose(fp);
return(0);
}
示例10: get_or_create_fileset_record
bool get_or_create_fileset_record(JCR *jcr)
{
FILESET_DBR fsr;
/*
* Get or Create FileSet record
*/
memset(&fsr, 0, sizeof(FILESET_DBR));
bstrncpy(fsr.FileSet, jcr->res.fileset->hdr.name, sizeof(fsr.FileSet));
if (jcr->res.fileset->have_MD5) {
struct MD5Context md5c;
unsigned char digest[MD5HashSize];
memcpy(&md5c, &jcr->res.fileset->md5c, sizeof(md5c));
MD5Final(digest, &md5c);
/*
* Keep the flag (last arg) set to false otherwise old FileSets will
* get new MD5 sums and the user will get Full backups on everything
*/
bin_to_base64(fsr.MD5, sizeof(fsr.MD5), (char *)digest, MD5HashSize, false);
bstrncpy(jcr->res.fileset->MD5, fsr.MD5, sizeof(jcr->res.fileset->MD5));
} else {
Jmsg(jcr, M_WARNING, 0, _("FileSet MD5 digest not found.\n"));
}
if (!jcr->res.fileset->ignore_fs_changes ||
!db_get_fileset_record(jcr, jcr->db, &fsr)) {
if (!db_create_fileset_record(jcr, jcr->db, &fsr)) {
Jmsg(jcr, M_ERROR, 0, _("Could not create FileSet \"%s\" record. ERR=%s\n"),
fsr.FileSet, db_strerror(jcr->db));
return false;
}
}
jcr->jr.FileSetId = fsr.FileSetId;
bstrncpy(jcr->FSCreateTime, fsr.cCreateTime, sizeof(jcr->FSCreateTime));
Dmsg2(119, "Created FileSet %s record %u\n", jcr->res.fileset->hdr.name,
jcr->jr.FileSetId);
return true;
}
示例11: main
int
main(int argc, char *argv[]) {
char buffer[1024];
unsigned char mac[MD5_DIGEST_LENGTH];
unsigned char buf[MD5_DIGEST_STRING_LENGTH];
MD5_CTX ctx;
int ret;
if (argc != 2) {
printf("Usage: %s <mac>\n", *argv);
return 1;
}
ret = read(0, buffer, 1024);
if (ret == -1)
return 1;
printf("User message = [%s]\n", buffer);
printf("User mac = [%s]\n", argv[1]);
MD5Init(&ctx);
MD5Update(&ctx, (const u_int8_t *) SECRET, strlen(SECRET));
MD5Update(&ctx, (const u_int8_t *) buffer, ret);
MD5Final(mac, &ctx);
shexdigest(buf, mac);
printf("[Hint] Expected mac = [%s]\n", buf);
if (!strcmp((char *)buf, argv[1]) && !lstrstr(buffer, ret, "flag", 4))
printf("Good!\n");
else
printf("Nope\n");
return 0;
}
示例12: nas_rand128
void
nas_rand128(uint8 *rand128)
{
static int dev_random_fd = -1;
struct timeval tv;
struct timezone tz;
MD5_CTX md5;
if (dev_random_fd == -1)
/* Use /dev/urandom because /dev/random, when it works at all,
* won't return anything when its entropy pool runs short and
* we can't control that. /dev/urandom look good enough.
*/
dev_random_fd = open("/dev/urandom", O_RDONLY|O_NONBLOCK);
if (dev_random_fd != -1)
read(dev_random_fd, rand128, 16);
else {
gettimeofday(&tv, &tz);
tv.tv_sec ^= rand();
MD5Init(&md5);
MD5Update(&md5, (unsigned char *) &tv, sizeof(tv));
MD5Update(&md5, (unsigned char *) &tz, sizeof(tz));
MD5Final(rand128, &md5);
}
}
示例13: time_trial
/* Measures the time to digest TEST_BLOCK_COUNT TEST_BLOCK_LEN-byte
blocks.
*/
static void time_trial(void)
{
MD5_CTX context;
uint32 endTime, startTime;
unsigned char block[TEST_BLOCK_LEN], digest[16];
unsigned int i;
printf
("MD5 time trial. Digesting %d %d-byte blocks ...",
TEST_BLOCK_LEN, TEST_BLOCK_COUNT);
/* Initialize block */
for(i = 0; i < TEST_BLOCK_LEN; i++)
block[i] =(unsigned char)(i & 0xff);
/* Start timer */
startTime = VmGetClock();
/* Digest blocks */
MD5Init(&context);
for(i = 0; i < TEST_BLOCK_COUNT; i++)
MD5Update(&context, block, TEST_BLOCK_LEN);
MD5Final(digest, &context);
/* Stop timer */
endTime = VmGetClock();
printf(" done\n");
printf("Digest = ");
print_digest(digest);
printf("\nTime = %ld ms\n",(long)(endTime-startTime));
printf
("Speed = %ld bytes/second\n",
(long)TEST_BLOCK_LEN *(long)TEST_BLOCK_COUNT *(long) 1000/(endTime-startTime));
}
示例14: md5sum
bool md5sum(const fs::path &path, md5digest &digest)
{
try {
Exiv2::FileIo io(path.file_string());
if (io.open() != 0)
return false;
Exiv2::IoCloser closer(io);
Exiv2::byte buff[4096];
MD5_CTX context;
MD5Init(&context);
long read_count = io.read(buff, 4096);
while(read_count) {
MD5Update(&context, buff, read_count);
read_count = io.read(buff, 4096);
}
MD5Final(digest, &context);
return true;
}
catch (std::exception& ) {
return false;
}
}
示例15: malloc
//
// this works in lockstep with ::create to populate
// the per chromosome header fields size and md5
// checksum.
//
// It relies on header->elementCount being set to
// the data length loaded so far ... not the ultimate
// reference length.
//
bool GenomeSequence::setChromosomeMD5andLength(uint32_t whichChromosome)
{
if (whichChromosome>=header->_chromosomeCount) return true;
ChromosomeInfo *c = &header->_chromosomes[whichChromosome];
c->size = header->elementCount - c->start;
MD5_CTX md5Context;
uint8_t md5Signature[MD5_DIGEST_LENGTH];
//
// it's easier to ensure we do this right if we just do it
// in one big chunk:
//
char *md5Buffer = (char *) malloc(c->size);
MD5Init(&md5Context);
for (genomeIndex_t i = 0; i < c->size; i ++)
{
md5Buffer[i] = (*this)[c->start + i];
}
MD5Update(&md5Context, (unsigned char *) md5Buffer, c->size);
MD5Final((unsigned char *) &md5Signature, &md5Context);
free(md5Buffer);
for (int i=0; i<MD5_DIGEST_LENGTH; i++)
{
// cheesy but works:
sprintf(c->md5+2*i, "%02x", md5Signature[i]);
}
// redundant, strictly speaking due to sprintf NUL terminating
// it's output strings, but put it here anyway.
c->md5[2*MD5_DIGEST_LENGTH] = '\0';
return false;
}