// computes an RSA-MD5 signature over 'buf' using 'priv_key'
// signature data is returned is 'sig_buf' which should be at least
// SIGNATURE_LEN bytes in size.  
// Method returns 0 on success.   
int get_signature(char *buf, unsigned int buf_size, RSA *priv_key,
                   unsigned char *sig_buf, unsigned int *sig_len) {

  unsigned char digest[16];
  unsigned int digest_len = 16;
  MD5_CTX md5;
  MD5_Init(&md5);
  MD5_Update(&md5, (unsigned char*)buf, buf_size);
  MD5_Final(digest, &md5);

  int ret_val = RSA_sign(NID_md5, digest, digest_len, 
			sig_buf, sig_len, priv_key);
  if(!ret_val) {
      unsigned long e = ERR_get_error();
      DPRINTF(DEBUG_ERROR,"RSA_sign error: %s", ERR_error_string(e, buf));
      return 1;
  }
 
  return 0;
}
Ejemplo n.º 2
0
string md5sum(const char * str, int len)
{
	int n;
    MD5_CTX ctx;
    char buf[SLICECAP];
    unsigned char out[MD5_DIGEST_LENGTH];
    string md5str;

	MD5_Init(&ctx);
	MD5_Update(&ctx, str, len);
    MD5_Final(out, &ctx);

    for(n = 0; n< MD5_DIGEST_LENGTH; n++)
	{
		snprintf(buf, SLICECAP, "%02x", out[n]);
		md5str += buf;
	}

    return md5str;     
}
Ejemplo n.º 3
0
/* Get the next rsync block of a file. */
int
rsync_nextblock(struct rsyncfile *rf)
{
	MD5_CTX ctx;
	size_t blocksize;

	if (rf->blockptr >= rf->end)
		return (0);
	blocksize = min((size_t)(rf->end - rf->blockptr), rf->blocksize);
	/* Calculate MD5 of the block. */
	MD5_Init(&ctx);
	MD5_Update(&ctx, rf->blockptr, blocksize);
	MD5_End(rf->blockmd5, &ctx);

	rf->rsum = rsync_rollsum(rf->blockptr, blocksize);
	snprintf(rf->rsumstr, RSUM_SIZE, "%x", rf->rsum);
	rf->blocknum++;
	rf->blockptr += blocksize;
	return (1);
}
static int calculate_md5(char *str, const char *path) {
    FILE *fd;
    fd = fopen(path, "r");
    if (fd != NULL) {
        MD5_CTX c;
        size_t i;
        static unsigned char buf[BUFSIZE];
        unsigned char md5dig[MD5_DIGEST_LENGTH];
        MD5_Init(&c);
        while ((i = fread(buf, 1, BUFSIZE, fd)) > 0)
            MD5_Update(&c, buf, i);
        MD5_Final(&(md5dig[0]), &c);
        fclose(fd);
        to_md5_hash(str, md5dig);
    } else {
       return 1;
    }

    return 0;
}
Ejemplo n.º 5
0
/*
 * Selects the cipher, and keys if by computing the MD5 checksum of the
 * passphrase and using the resulting 16 bytes as the key.
 */
int
cipher_set_key_string(struct sshcipher_ctx *cc, struct sshcipher *cipher,
    const char *pphrase, int do_encrypt)
{
	MD5_CTX md;
	u_char digest[16];
	int ret = SSH_ERR_LIBCRYPTO_ERROR;

	if (MD5_Init(&md) != 1 ||
	    MD5_Update(&md, (const u_char *)pphrase, strlen(pphrase)) != 1 ||
	    MD5_Final(digest, &md) != 1)
		goto out;

	ret = cipher_init(cc, cipher, digest, 16, NULL, 0, do_encrypt);

 out:
	memset(digest, 0, sizeof(digest));
	memset(&md, 0, sizeof(md));
	return ret;
}
Ejemplo n.º 6
0
ClientWardenModule* WardenWin::GetModuleForClient()
{
    ClientWardenModule *mod = new ClientWardenModule;

    uint32 length = sizeof(Module.Module);

    // data assign
    mod->CompressedSize = length;
    mod->CompressedData = new uint8[length];
    memcpy(mod->CompressedData, Module.Module, length);
    memcpy(mod->Key, Module.ModuleKey, 16);

    // md5 hash
    MD5_CTX ctx;
    MD5_Init(&ctx);
    MD5_Update(&ctx, mod->CompressedData, length);
    MD5_Final((uint8*)&mod->Id, &ctx);

    return mod;
}
Ejemplo n.º 7
0
ClientWardenModule *WardenMac::GetModuleForClient(WorldSession* /*session*/)
{
    ClientWardenModule *mod = new ClientWardenModule;

    uint32 len = sizeof(Module_0DBBF209A27B1E279A9FEC5C168A15F7_Data);

    // data assign
    mod->CompressedSize = len;
    mod->CompressedData = new uint8[len];
    memcpy(mod->CompressedData, Module_0DBBF209A27B1E279A9FEC5C168A15F7_Data, len);
    memcpy(mod->Key, Module_0DBBF209A27B1E279A9FEC5C168A15F7_Key, 16);
        
    // md5 hash
    MD5_CTX ctx;
    MD5_Init(&ctx);
    MD5_Update(&ctx, mod->CompressedData, len);
    MD5_Final((uint8*)&mod->ID, &ctx);

    return mod;
}
Ejemplo n.º 8
0
void generate_md5_hashes(char* input_data, int count, unsigned char* result)
{
    MD5_CTX md5;
    
    unsigned char md5_result[16] = {0};

    int i;
    for(i = 0; i < count; i++)
    {
	MD5_Init(&md5);
	
	MD5_Update(&md5, input_data, strlen(input_data));
	input_data += INPUT_MAX_LENGTH;
	
	MD5_Final(md5_result, &md5);

	memcpy(result, md5_result, 16);
	result += 16;
    }
}
Ejemplo n.º 9
0
/*
 * Compute the MD5 checksum of a file.  The md parameter must
 * point to a buffer containing at least MD5_DIGEST_SIZE bytes.
 *
 * Do not confuse OpenSSL's MD5_DIGEST_LENGTH with our own
 * MD5_DIGEST_SIZE macro.
 */
int
MD5_File(char *path, char *md)
{
	char buf[1024];
	MD5_CTX ctx;
	ssize_t n;
	int fd;

	fd = open(path, O_RDONLY);
	if (fd == -1)
		return (-1);
	MD5_Init(&ctx);
	while ((n = read(fd, buf, sizeof(buf))) > 0)
		MD5_Update(&ctx, buf, n);
	close(fd);
	if (n == -1)
		return (-1);
	MD5_End(md, &ctx);
	return (0);
}
Ejemplo n.º 10
0
static int lua_md5(lua_State* L)
{
    size_t l=0;

    const char* s=luaL_checklstring(L,1,&l);

    MD5_CTX ctx;
    MD5_Init(&ctx);
    MD5_Update(&ctx,(unsigned char*)s,l);

    unsigned char md[16];
    MD5_Final(md,&ctx);

    char buf[sizeof(md)*2];
    to_hex(md,buf,sizeof(md));
 
    lua_pushlstring(L,buf,sizeof(buf));

    return 1;
}
Ejemplo n.º 11
0
ClientWardenModule *WardenWin::GetModuleForClient(WorldSession *session)
{
    ClientWardenModule *mod = new ClientWardenModule;

    uint32 length = sizeof(Module_79C0768D657977D697E10BAD956CCED1_Data);

    // data assign
    mod->CompressedSize = length;
    mod->CompressedData = new uint8[length];
    memcpy(mod->CompressedData, Module_79C0768D657977D697E10BAD956CCED1_Data, length);
    memcpy(mod->Key, Module_79C0768D657977D697E10BAD956CCED1_Key, 16);

    // md5 hash
    MD5_CTX ctx;
    MD5_Init(&ctx);
    MD5_Update(&ctx, mod->CompressedData, length);
    MD5_Final((uint8*)&mod->Id, &ctx);

    return mod;
}
Ejemplo n.º 12
0
static char *md5_fd(int fd)
{
    MD5_CTX ctx;
    unsigned char buf[BUFSIZ], output[16];
    ssize_t n;

    MD5_Init(&ctx);

    while ((n = read(fd, buf, sizeof(buf))) > 0 || errno == EINTR) {
        if (n < 0)
            continue;
        MD5_Update(&ctx, buf, n);
    }

    if (n < 0)
        return NULL;

    MD5_Final(output, &ctx);
    return hex_representation(output, 16);
}
Ejemplo n.º 13
0
char * md5_identity(void *data, int len)
{
    unsigned char hash[16];
    char* result;
    int ptr,i;

    result = (char*)malloc(sizeof(char)*512);
    memset(result, 0, sizeof(result));
    MD5_CTX ctx;
    MD5_Init(&ctx);
    MD5_Update(&ctx,(char*)data,len);
    MD5_Final(hash,&ctx);

    ptr = 0;
    for(i=0;i<16;i++)
    {
        ptr += sprintf(result+ptr, "%02x", hash[i]);
    }
    return result;
}
Ejemplo n.º 14
0
//Return value is on the heap.
char* md5(const char *filename) {

	//Open the input file.
	FILE *in_file = fopen(filename, "rb");

	if (!in_file) {
		printf ("%s can't be opened.\n", filename);
		return NULL;
	}

	//Initialise the md5 function.
	MD5_CTX md_context;
	MD5_Init (&md_context);
	
	//Read in the data from the file and feed it to the md5 function.
	int bytes;
	unsigned char data[1024];

	while ((bytes = fread(data, 1, 1024, in_file)) != 0) {
		MD5_Update(&md_context, data, bytes);
	}

	//Recieve the final md5 value inside c.
	unsigned char c[MD5_DIGEST_LENGTH];
	MD5_Final(c,&md_context);

	//Allocate memory for the return value.
	char tmp[2];
	char *hash = malloc((MD5_DIGEST_LENGTH * 2) + 1);

	//Format the md5 digits as chars.
	for (int i = 0; i < MD5_DIGEST_LENGTH; i++) {
		sprintf(tmp, "%02x", c[i]);
		memcpy(hash+(i*2), tmp, 2);
	}

	hash[MD5_DIGEST_LENGTH*2] = '\0';
	fclose (in_file);

	return hash;
}
Ejemplo n.º 15
0
bool Condor_MD_MAC::addMDFile(const char * filePathName)
{
#ifdef HAVE_EXT_OPENSSL
	int fd;

    fd = safe_open_wrapper_follow(filePathName, O_RDONLY | O_LARGEFILE, 0);
    if (fd < 0) {
        dprintf(D_ALWAYS,
                "addMDFile: can't open %s: %s\n",
                filePathName,
                strerror(errno));
        return false;
    }

	unsigned char *buffer;	

	buffer = (unsigned char *)calloc(1024*1024, 1);
	ASSERT(buffer != NULL);

	bool ok = true;
	ssize_t count = read(fd, buffer, 1024*1024); 
	while( count > 0) {
		MD5_Update(&(context_->md5_), buffer, count); 
		memset(buffer, 0, 1024*1024);
		count = read(fd, buffer, 1024*1024); 
	}
	if (count == -1) {
		dprintf(D_ALWAYS,
		        "addMDFile: error reading from %s: %s\n",
		        filePathName,
		        strerror(errno));
		ok = false;
	}

	close(fd);
	free(buffer);
	return ok;
#else
	return false;
#endif
}
Ejemplo n.º 16
0
static int
rc4_hmac_md5_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
    const unsigned char *in, size_t len)
{
	EVP_RC4_HMAC_MD5 *key = data(ctx);
#if defined(STITCHED_CALL)
	size_t	rc4_off = 32-1-(key->ks.x&(32-1)),	/* 32 is $MOD from rc4_md5-x86_64.pl */
	md5_off = MD5_CBLOCK - key->md.num,
	    blocks;
	unsigned int l;
	extern unsigned int OPENSSL_ia32cap_P[];
#endif
	size_t	plen = key->payload_length;

	if (plen != NO_PAYLOAD_LENGTH && len != (plen + MD5_DIGEST_LENGTH))
		return 0;

	if (ctx->encrypt) {
		if (plen == NO_PAYLOAD_LENGTH)
			plen = len;
#if defined(STITCHED_CALL)
		/* cipher has to "fall behind" */
		if (rc4_off > md5_off)
			md5_off += MD5_CBLOCK;

		if (plen > md5_off &&
		    (blocks = (plen - md5_off) / MD5_CBLOCK) &&
		    (OPENSSL_ia32cap_P[0]&(1 << 20)) == 0) {
			MD5_Update(&key->md, in, md5_off);
			RC4(&key->ks, rc4_off, in, out);

			rc4_md5_enc(&key->ks, in + rc4_off, out + rc4_off,
			    &key->md, in + md5_off, blocks);
			blocks *= MD5_CBLOCK;
			rc4_off += blocks;
			md5_off += blocks;
			key->md.Nh += blocks >> 29;
			key->md.Nl += blocks <<= 3;
			if (key->md.Nl < (unsigned int)blocks)
				key->md.Nh++;
		} else {
Ejemplo n.º 17
0
int stun_produce_integrity_key_str(u08bits *uname, u08bits *realm, u08bits *upwd, u08bits *key)
{
	MD5_CTX ctx;
	size_t ulen = strlen((s08bits*)uname);
	size_t rlen = strlen((s08bits*)realm);
	size_t plen = strlen((s08bits*)upwd);
	u08bits *str = (u08bits*)malloc(ulen+1+rlen+1+plen+1);

	strcpy((s08bits*)str,(s08bits*)uname);
	str[ulen]=':';
	strcpy((s08bits*)str+ulen+1,(s08bits*)realm);
	str[ulen+1+rlen]=':';
	strcpy((s08bits*)str+ulen+1+rlen+1,(s08bits*)upwd);

	MD5_Init(&ctx);
	MD5_Update(&ctx,str,ulen+1+rlen+1+plen);
	MD5_Final(key,&ctx);
	free(str);

	return 0;
}
Ejemplo n.º 18
0
void md5(FILE * f)
{
 MD5_CTX ctx;
 unsigned char tab[MD5_DIGEST_LENGTH];
 MD5_Init(&ctx);
 unsigned char bufor[size];
 int read;
 
 while (!feof(f))
       {
        read = fread(bufor, 1, size, f);
        MD5_Update(&ctx, bufor, read);
       }
 
 MD5_Final(tab, &ctx);
 
 int i;
 for (i = 0; i < MD5_DIGEST_LENGTH; i++)
     printf("%02x", tab[i]);
 printf("\n");   
}
Ejemplo n.º 19
0
// Function which calculates MD5 for comparison with Response Authenticator
void GetSubscriberMD5(BYTE subResponseAuth[MD5_DIGEST_LENGTH], RADIUS_PACKET *aaaData, SUBSCRIBER *sub) {

	int i, j;
	BYTE hash[MAX_ARGUMENT_LENGTH];
	MD5_CTX context;

	// Init MD5
	MD5_Init(&context);
	// Create string to be hashed and execute MD5 hashing
	bzero(hash, MAX_ARGUMENT_LENGTH);
	hash[0] = aaaData->code;
	hash[1] = aaaData->identifier;
	memcpy(hash + 2, (unsigned char *)&aaaData->length, 2);
	memcpy(hash + 4, sub->aaaAuthenticator, 16);
	memcpy(hash + 20, aaaData->options, htons(aaaData->length) - RADIUS_HEADER_LENGTH);
	memcpy(hash + ntohs(aaaData->length), Radius_secret, strlen(Radius_secret));
	MD5_Update (&context, hash, ntohs(aaaData->length) + strlen(Radius_secret));
	MD5_Final (subResponseAuth, &context);

	return;
}
Ejemplo n.º 20
0
int gen_md5(headers_t *headers, char *target) {
    unsigned long key1 = parse_hixie76_key(headers->key1);
    unsigned long key2 = parse_hixie76_key(headers->key2);
    char *key3 = headers->key3;

    MD5_CTX c;
    char in[HIXIE_MD5_DIGEST_LENGTH] = {
        key1 >> 24, key1 >> 16, key1 >> 8, key1,
        key2 >> 24, key2 >> 16, key2 >> 8, key2,
        key3[0], key3[1], key3[2], key3[3],
        key3[4], key3[5], key3[6], key3[7]
    };

    MD5_Init(&c);
    MD5_Update(&c, (void *)in, sizeof in);
    MD5_Final((void *)target, &c);

    target[HIXIE_MD5_DIGEST_LENGTH] = '\0';

    return 1;
}
Ejemplo n.º 21
0
static ERL_NIF_TERM
update(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    md5ctx* ctx;
    ErlNifBinary bin;

    if(argc != 2)
        return enif_make_badarg(env);
    if(!enif_get_resource(env, argv[0], md5_type, (void**) &ctx))
        return enif_make_badarg(env);
    if(!enif_inspect_binary(env, argv[1], &bin))
        return enif_make_badarg(env);

    if(ctx->finalized)
        return make_atom(env, "already_finalized");

    if(!MD5_Update(&(ctx->md5), bin.data, bin.size))
        return make_atom(env, "update_error");

    return make_atom(env, "ok");
}
Ejemplo n.º 22
0
void generate_data( dcp_info_t * info ) { 
    // init static random generator
    srand(STATIC_SEED);

    MD5_CTX ctx;
    int idx;
    for( idx=0; idx<info->nbuffer; ++idx) {
        MD5_Init(&ctx);
        uintptr_t ptr = (uintptr_t) info->buffer[idx];
        uintptr_t ptr_e = (uintptr_t)info->buffer[idx] + (uintptr_t)info->size[idx];
        while ( ptr < ptr_e ) {
            unsigned int rui = (unsigned int) rand();
            int init_size = ( (ptr_e - ptr) > UI_UNIT ) ? UI_UNIT : ptr_e-ptr;
            memcpy((void*)ptr, &rui, init_size);
            MD5_Update( &ctx, (void*)ptr, init_size); 
            ptr += init_size;
        }
        assert( ptr == ptr_e );
        MD5_Final(info->hash[idx], &ctx);
    }
}
Ejemplo n.º 23
0
static int crypt_all(int *pcount, struct db_salt *salt)
{
	int count = *pcount;
	int index = 0;

#ifdef _OPENMP
#pragma omp parallel for
#endif
#if defined(_OPENMP) || MAX_KEYS_PER_CRYPT > 1
	for (index = 0; index < count; index++)
#endif
	{
		unsigned char hash[16];
		MD5_CTX ctx;
		MD5_Init(&ctx);
		MD5_Update(&ctx, saved_key[index], strlen(saved_key[index]));
		MD5_Final(hash, &ctx);
		hex_encode(hash, 16, (unsigned char*)crypt_out[index]);
	}
	return count;
}
Ejemplo n.º 24
0
// Password is did_u_really_reverse_me
int verify_password(char *pass) {
	MD5_CTX c;
	unsigned char digest[16] = {
		0x87, 0xe0, 0xbe, 0x2f, 0x4f, 0x39, 0x86, 0x29, 
		0x5d, 0x86, 0xe3, 0x27, 0xaf, 0x53, 0xee, 0xd2
	};
	unsigned char pass_digest[16];
	int i;

	MD5_Init(&c);
	MD5_Update(&c, pass, strlen(pass));
	MD5_Final(pass_digest, &c);

	for (i = 0; i < 16; i++) {
		if (digest[i] != pass_digest[i]) {
			return -1;
		}
	}

	return 0;
}
Ejemplo n.º 25
0
Archivo: bedup.c Proyecto: kaptk2/burp
static int get_full_cksum(struct file *f, FILE **fp)
{
	size_t s=0;
	MD5_CTX md5;
	static char buf[FULL_CHUNK];
	unsigned char checksum[MD5_DIGEST_LENGTH+1];

	if(*fp) fseek(*fp, 0, SEEK_SET);
	else if(!(*fp=open_file(f)))
	{
		f->full_cksum=0;
		return 0;
	}

	if(!MD5_Init(&md5))
	{
		logp("MD5_Init() failed\n");
		return -1;
	}

	while((s=fread(buf, 1, FULL_CHUNK, *fp))>0)
	{
		if(!MD5_Update(&md5, buf, s))
		{
			logp("MD5_Update() failed\n");
			return -1;
		}
		if(s<FULL_CHUNK) break;
	}

	if(!MD5_Final(checksum, &md5))
	{
		logp("MD5_Final() failed\n");
		return -1;
	}

	memcpy(&(f->full_cksum), checksum, sizeof(unsigned));

	return 0;
}
Ejemplo n.º 26
0
int check_fmhdr(char *b, ssize_t len) {
  if (gV > 1) puts("check_fmhdr");

  MD5_CTX context;
  frm_t *buf = (frm_t *) b;

  unsigned char cmp_digest[0x10] = {0},    hdr_digest[0x10];
  unsigned char cmp_signature[0x20] = {0}, hdr_signature[0x20];
  unsigned char cmp_randseq[0x10] = {0},   hdr_randseq[0x10];

  memcpy(hdr_signature, buf->h.fm_signature, sizeof(hdr_signature));
  memset(buf->h.fm_signature, 0, 0x20);
  memcpy(hdr_digest,    buf->h.fm_digest,    sizeof(hdr_digest));
  memset(buf->h.fm_digest,    0, 0x10);

  MD5_Init(&context);							// Compute hash
  MD5_Update(&context, buf, len);
  MD5_Final(cmp_digest, &context);

  memcpy(hdr_randseq,   buf->h.fm_randseq,   sizeof(hdr_randseq));
  memset(buf->h.fm_randseq, 0, sizeof(buf->h.fm_randseq));
  nsdigest(cmp_randseq, (char *)buf, len);				// Compute digest
  memcpy(buf->h.fm_randseq,   cmp_randseq, sizeof(buf->h.fm_randseq));
  memcpy(buf->h.fm_digest,    cmp_digest, sizeof(buf->h.fm_digest));
  memcpy(buf->h.fm_signature, cmp_signature, sizeof(buf->h.fm_signature));

  if (memcmp(cmp_digest, hdr_digest, sizeof(hdr_digest))) {
    puts("Header digest error");
  print_digest(cmp_digest); print_digest(hdr_digest);
    return -1;
  }
  if (memcmp(cmp_randseq, hdr_randseq, sizeof(hdr_randseq))) {
    puts("Header randseq error");
  print_digest_x(cmp_randseq, 0x20); print_digest_x(hdr_randseq, 0x20);
    return -1;
  }
  puts ("Header OK!");
  return 0;
}
Ejemplo n.º 27
0
static void msend_ack_md5(int s, mfile *m)
{
  int r;
  unsigned char hash[16];
  unsigned char buff[8192];
  mfile *d = m->link;
  if(!d){
    msend_shot(s, m);
    return;
  }
  r = read(d->fd, buff, sizeof(buff));
  if(r > 0){
    MD5_Update(&(d->md5), buff, r);
    return;
  }
  if(r == -1){
    if(errno == EINTR){
      return;
    }
    d->mdata.head.error  = errno;
    d->mdata.head.nstate = MAKUO_RECVSTATE_READERROR;
    lprintf(0, "[error] %s: file read error %s\n", __func__, d->fn);
    MD5_Final(hash, &(d->md5));
  }else{
    MD5_Final(hash, &(d->md5));
    if(!memcmp(hash, d->mdata.data, 16)){
      d->mdata.head.nstate = MAKUO_RECVSTATE_MD5OK;
    }else{
      d->mdata.head.nstate = MAKUO_RECVSTATE_MD5NG;
    }
  }
  m->mdata.head.error  = d->mdata.head.error;
  m->mdata.head.nstate = d->mdata.head.nstate;
  close(d->fd);
  d->fd = -1;
  d->link = NULL;
  m->link = NULL;
  msend_shot(s, m);
}
Ejemplo n.º 28
0
char *check_validity(
    const char *certPath, const char *origFile, unsigned char *signature,
    char* caPath
) {
    MD5_CTX md5CTX;
    int rbytes;
    unsigned char md5_md[MD5_DIGEST_LENGTH],  rbuf[2048];

    SSL_load_error_strings();
    SSL_library_init();

    if (!is_file(origFile)) {
        return NULL;
    }
    FILE* of = boinc_fopen(origFile, "r");
    if (!of) return NULL;
    MD5_Init(&md5CTX);
    while (0 != (rbytes = (int)fread(rbuf, 1, sizeof(rbuf), of))) {
	    MD5_Update(&md5CTX, rbuf, rbytes);
    }
    MD5_Final(md5_md, &md5CTX);
    fclose(of);

    DIRREF dir = dir_open(certPath);

    char file[MAXPATHLEN];
    while (!dir_scan(file, dir, sizeof(file))) {
        char fpath[MAXPATHLEN];
	    snprintf(fpath, sizeof(fpath), "%s/%s", certPath, file);
        // TODO : replace '128'  
	    if (check_validity_of_cert(fpath, md5_md, signature, 128, caPath)) {
	        dir_close(dir);
	        return strdup(fpath);
	    }
    }

    dir_close(dir);
    return NULL;
}
Ejemplo n.º 29
0
u_int
res_nrandomid(res_state statp) {
	struct timeval now;
	u_int16_t u16;
	MD5_CTX ctx;
	u_char *rnd = statp->_rnd == NULL ? srnd : statp->_rnd;

	gettimeofday(&now, NULL);
	u16 = (u_int16_t) (now.tv_sec ^ now.tv_usec);
	memcpy(rnd + 14, &u16, 2);
#ifndef HAVE_MD5
	MD5_Init(&ctx);
	MD5_Update(&ctx, rnd, 16);
	MD5_Final(rnd, &ctx);
#else
	MD5Init(&ctx);
	MD5Update(&ctx, rnd, 16);
	MD5Final(rnd, &ctx);
#endif
	memcpy(&u16, rnd + 14, 2);
	return ((u_int) u16);
}
Ejemplo n.º 30
0
void
doit (void)
{
  MD5_CTX c;
  unsigned char md[MD5_DIGEST_LENGTH];

  if (!gnutls_check_version (LIBGNUTLS_VERSION))
    success ("gnutls_check_version ERROR\n");

  MD5_Init (&c);
  MD5_Update (&c, "abc", 3);
  MD5_Final (&(md[0]), &c);

  if (memcmp (md, "\x90\x01\x50\x98\x3c\xd2\x4f\xb0"
	      "\xd6\x96\x3f\x7d\x28\xe1\x7f\x72", sizeof (md)) != 0)
    {
      hexprint (md, sizeof (md));
      fail ("MD5 failure\n");
    }
  else
    success ("MD5 OK\n");
}