Ejemplo n.º 1
0
/*
 * 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;
}
Ejemplo n.º 2
0
// 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;
}
Ejemplo n.º 3
0
Archivo: load.c Proyecto: visy/turha
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);
}
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
0
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);
}
Ejemplo n.º 6
0
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);
}
Ejemplo n.º 7
0
char *websMD5binary(unsigned char *buf, int length)
{
    const char		*hex = "0123456789abcdef";
    MD5_CONTEXT		md5ctx;
    unsigned char	hash[HASH_SIZE];
    char			*r, *strReturn;
	char			result[(HASH_SIZE * 2) + 1];
    int				i;

/*
 *	Take the MD5 hash of the string argument.
 */
    MD5Init(&md5ctx);
    MD5Update(&md5ctx, buf, (unsigned int)length);
    MD5Final(hash, &md5ctx);

/*
 *	Prepare the resulting hash string
 */
    for (i = 0, r = result; i < 16; i++) {
		*r++ = hex[hash[i] >> 4];
		*r++ = hex[hash[i] & 0xF];
    }

/*
 *	Zero terminate the hash string
 */
    *r = '\0';

/*
 *	Allocate a new copy of the hash string
 */
	strReturn = balloc(B_L, sizeof(result));
	strcpy(strReturn, result);

    return strReturn;
}
Ejemplo n.º 8
0
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;	
}
Ejemplo n.º 9
0
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;

}
Ejemplo n.º 10
0
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);
}
Ejemplo n.º 11
0
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;
}
Ejemplo n.º 12
0
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;
}
Ejemplo n.º 13
0
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);
	}
}
Ejemplo n.º 14
0
/* 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));
}
Ejemplo n.º 15
0
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;
    }
}
Ejemplo n.º 16
0
//
// 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;
}
Ejemplo n.º 17
0
static void
upnp_gen_uuid(char *uuid, char *deviceType, unsigned char mac[6])
{
	unsigned char new_uuid[16];

	MD5_CTX mdContext;

	/* Generate hash */
	MD5Init(&mdContext);
	MD5Update(&mdContext, mac, 6);
	MD5Update(&mdContext, (unsigned char *)deviceType, strlen(deviceType));
	MD5Final(new_uuid, &mdContext);

	sprintf(uuid,
		"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
		new_uuid[0],  new_uuid[1],  new_uuid[2],  new_uuid[3],
		new_uuid[4],  new_uuid[5],  new_uuid[6],  new_uuid[7],
		new_uuid[8],  new_uuid[9],  new_uuid[10], new_uuid[11],
		new_uuid[12], new_uuid[13], new_uuid[14], new_uuid[15]);

	uuid[36] = '\0';

	return;
}
Ejemplo n.º 18
0
/* Digests an entire file and puts the result into digest.
 */
void MDFile (unsigned char digest[16], char *filename) {
    FILE *file;
    MD5_CTX context;
    int len;
    unsigned char buffer[1024];

    if ((file = fopen (filename, "rb")) == NULL)
	    printf ("%s can't be opened\n", filename);

    else {
	    MD5Init (&context);
	    while ((len = fread (buffer, 1, 1024, file)) != 0)
	        MD5Update (&context, buffer, len);
	    MD5Final (digest, &context);

	    fclose (file);
            /*
	    printf ("MD%d (%s) = ", MD, filename);
	    MDPrint (digest);
	    printf ("\n");
            */
        
    }
}
Ejemplo n.º 19
0
/* Encrypt or decrypt a MPPE message in place */
void
mppe_crypt(unsigned char salt[2],		/* 2 bytes Salt */
	   unsigned char *text,	int text_len,	/* Multiple of 16 bytes String */
	   unsigned char *key, int key_len,	/* Shared secret */
	   unsigned char vector[16],		/* 16 bytes Request Authenticator vector */
	   int encrypt)				/* Encrypt if 1 */
{
	unsigned char b[16], c[16], *p;
	MD5_CTX md5;
	int i;

	/* Initial cipher block is Request Authenticator vector */
	bcopy(vector, c, 16);
	for (p = text; &p[15] < &text[text_len]; p += 16) {
		MD5Init(&md5);
		/* Add shared secret */
		MD5Update(&md5, key, key_len);
		/* Add last cipher block */
		MD5Update(&md5, c, 16);
		/* Add salt */
		if (p == text)
			MD5Update(&md5, salt, 2);
		MD5Final(b, &md5);
		if (encrypt) {
			for (i = 0; i < 16; i++) {
				p[i] ^= b[i];
				c[i] = p[i];
			}
		} else {
			for (i = 0; i < 16; i++) {
				c[i] = p[i];
				p[i] ^= b[i];
			}
		}
	}
}
Ejemplo n.º 20
0
CString CryptManager::GetMD5( CString fn )
{
       struct MD5Context md5c;
       unsigned char digest[16];
       int iBytesRead;
       unsigned char buffer[1024];

       RageFile file;
       if( !file.Open( fn, RageFile::READ ) )
       {
               LOG->Warn( "GetMD5: Failed to open file '%s'", fn.c_str() );
               return "";
       }

       MD5Init(&md5c);
       while( !file.AtEOF() && file.GetError().empty() )
       {
               iBytesRead = file.Read( buffer, sizeof(buffer) );
               MD5Update(&md5c, buffer, iBytesRead);
       }
       MD5Final(digest, &md5c);

       return BinaryToHex( digest, sizeof(digest) );
}
Ejemplo n.º 21
0
//message handler for the client authentication dialog
BOOL CALLBACK AuthDlgProc(HWND hwndDlg, UINT message,
                          WPARAM wParam, LPARAM lParam) {
   switch (message) {
      case WM_INITDIALOG: {
         username[0] = 0;
         cnn.supstr(LAST_USER_SUPVAL, username, sizeof(username));
         SetDlgItemText(hwndDlg, IDC_USERNAME, username);
         return TRUE;
      }
      case WM_COMMAND:
         switch (LOWORD(wParam)) {
         case IDOK: {//OK Button
            char password[64];
            GetDlgItemText(hwndDlg, IDC_USERNAME, username, sizeof(username));
            GetDlgItemText(hwndDlg, IDC_PASSWORD, password, sizeof(password));

            cnn.supset(LAST_USER_SUPVAL, username);

            int pwlen = strlen(password);

            MD5Context ctx;
            MD5Init(&ctx);
            MD5Update(&ctx, (unsigned char*)password, pwlen);
            MD5Final(pwhash, &ctx);
            memset(password, 0, sizeof(password));

            EndDialog(hwndDlg, 1);
            return TRUE;
         }
         case IDCANCEL: //Cancel Button
            EndDialog(hwndDlg, 0);
            return TRUE;
         }
   }
   return FALSE;
}
Ejemplo n.º 22
0
///////////////////////////////////////////////////////////////////////////////
// MD5 of file
//	Input:
//		lpFileName	: full path of plugin
//	Output:
//		sha256		: SHA256 in plain-text (lower case)
//
BOOL MD5_Plugin(char *lpFileName, char *lpOutChecksum)
{
	if (lpFileName == NULL || lpOutChecksum == NULL)
		return FALSE;


	HANDLE hFile = CreateFile(lpFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);

	if (hFile == INVALID_HANDLE_VALUE)
		return FALSE;

	MD5_CTX context;

	MD5Init(&context);

	void *buffer = malloc(64000);

	DWORD dwBytesRead = 0;

	while(ReadFile(hFile, buffer, 64000, &dwBytesRead, NULL) == TRUE)
	{
		if (dwBytesRead == 0)	// end of file?
			break;

		MD5Update(&context, (byte *) buffer, (size_t) dwBytesRead);
	}

	CloseHandle(hFile);
	free(buffer);


	MD5Final(&context);
	hex2ascii(lpOutChecksum, (char *) context.digest, sizeof(context.digest));

	return TRUE;
}
Ejemplo n.º 23
0
int
portal_resp_authenticator(struct portal_packet_t *pack,
		struct portal_packet_t *req_pack,
		char *secret,
		size_t secretlen)
{
	MD5_CTX context;
	int packet_len = 0;

	if (PORTAL_PROTOCOL_MOBILE == eag_portal_protocol_type) {
		return 0;
	}
	
	memcpy(pack->payload.t.authenticator, 
		req_pack->payload.t.authenticator, PORTAL_AUTHLEN);

	MD5Init(&context);
	packet_len = portal_packet_get_length(pack);
	MD5Update(&context, (void *)pack, packet_len);
	MD5Update(&context, (uint8_t *)secret, secretlen);
	MD5Final(pack->payload.t.authenticator, &context);

	return 0;
}
Ejemplo n.º 24
0
void get_random_info(char seed[16]) {
  MD5_CTX c;
  typedef struct {
#ifdef HAVE_SYS_SYSINFO_H
      struct sysinfo s;
#else
      long clock_tick;
      long open_max;
      long stream_max;
      long expr_nest_max;
      long bc_scale_max;
      long bc_string_max;
#endif
      struct timeval t;
      char hostname[257];
  } randomness;
  randomness r;

  MD5Init(&c);

#ifdef HAVE_SYS_SYSINFO_H
  sysinfo(&r.s);
#else
  r.clock_tick    = sysconf(_SC_CLK_TCK);
  r.open_max      = sysconf(_SC_OPEN_MAX);
  r.stream_max    = sysconf(_SC_STREAM_MAX);
  r.expr_nest_max = sysconf(_SC_EXPR_NEST_MAX);
  r.bc_scale_max  = sysconf(_SC_BC_SCALE_MAX);
  r.bc_string_max = sysconf(_SC_BC_STRING_MAX);
#endif

  gettimeofday(&r.t, (struct timezone *)0);
  gethostname(r.hostname, 256);
  MD5Update(&c, &r, sizeof(randomness));
  MD5Final(seed, &c);
};
Ejemplo n.º 25
0
/* Sample code, not for use in production; see RFC 1750 */
void get_random_info(char seed[16])
{
    MD5_CTX c;
    struct {
        MEMORYSTATUS m;
        SYSTEM_INFO s;
        FILETIME t;
        LARGE_INTEGER pc;
        DWORD tc;
        DWORD l;
        char hostname[MAX_COMPUTERNAME_LENGTH + 1];
    } r;

    MD5Init(&c);
    GlobalMemoryStatus(&r.m);
    GetSystemInfo(&r.s);
    GetSystemTimeAsFileTime(&r.t);
    QueryPerformanceCounter(&r.pc);
    r.tc = GetTickCount();
    r.l = MAX_COMPUTERNAME_LENGTH + 1;
    GetComputerNameA(r.hostname, &r.l);
    MD5Update(&c, &r, sizeof r);
    MD5Final(seed, &c);
}
Ejemplo n.º 26
0
int testTempPwConvert(char *s1, char *s2) {
   char md5Buf[100];
   unsigned char digest[RESPONSE_LEN+2];
   char digestStr[100];
   MD5_CTX context;

   /* 
      Calcuate the temp password: a hash of s1 (the user's main
      password) and s2 (the value returned by chlGenTempPw).
   */

   memset(md5Buf, 0, sizeof(md5Buf));
   strncpy(md5Buf, s2, sizeof md5Buf);
   strncat(md5Buf, s1, sizeof md5Buf);

   MD5Init (&context);
   MD5Update (&context, (unsigned char*)md5Buf, sizeof md5Buf);
   MD5Final (digest, &context);

   md5ToStr(digest, digestStr);
   printf("digestStr (derived temp pw)=%s\n", digestStr);

   return(0);
}
Ejemplo n.º 27
0
decrypt(int key)
{
  struct stat st;  int size,fsize;  int *temp, result;     int rollingkey;    
  rollingkey = key;   
 
  infile = open ("pdf-encr", O_RDONLY);
  if (infile<0) { printf("input open error\n"); exit(0); }
  
  buf = 0;
  read(infile,&buf,4);
  size=buf; // get plaintext size

  // ciphertext has xtra 4 bytes (size) and padding 

  stat("pdf-encr", &st); fsize = st.st_size; // get ciphertext size
  if ((fsize < 8)||(size>fsize)||(size<(fsize-8))) {printf("file size sanity check failed\n");}; 

  outfile = open ("output-dec", O_RDWR|O_CREAT|O_TRUNC, 0700);
  if (outfile<0) { printf("output open error\n"); exit(0); }
  
  while ((n = read(infile, &buf, 4))> 0) {
      buf = buf ^ rollingkey; // doing the reverse of encrypt
      MD5Init(&mdContext);
      MD5Update(&mdContext, &rollingkey, 4);
      MD5Final(&mdContext);
      temp = (int *) &mdContext.digest[12]; 
      result = *temp; // result is 32 bits of MD5 of key
      rollingkey = rollingkey ^ result; // new key

      if (size >= 4) write(outfile, &buf, 4);  
      else lastbytes(outfile, size, buf);

      buf = 0;  // repeat, keep track of output size in size.
      size = size - 4;
  };
};
Ejemplo n.º 28
0
int TransferOK (time_t dNow)
{
char     szBuf [256];
    StopTransfer ();    // free resources

     // close MD5 computation
     MD5Final (sTC.m.ident, & sTC.m.ctx);

    // Semaphore released
    ReleaseSemaphore (hTftpClientSemaphore, 1, NULL);

    if (! sTC.bMultiFile)  
    {char szMD5 [33];
     int Ark;
     for (Ark=0 ; Ark<16; Ark++)
         wsprintf (szMD5 + 2*Ark, "%02x", sTC.m.ident[Ark]);
      wsprintf (szBuf, "%d block%s transferred in %d second%s\n %d block%s retransmitted\nMD5: %s",
                       sTC.nCount, // + (sTC.opcode==TFTP_RRQ ? 1 : 0),
                       PLURAL (sTC.nCount), // + (sTC.opcode==TFTP_RRQ ? 1 : 0)),
                       (int) (dNow-sTC.StartTime),
                       PLURAL (dNow-sTC.StartTime),
                       sTC.nTotRetrans,
                       PLURAL (sTC.nTotRetrans),
                       szMD5
            );
        CMsgBox (hTftpClientWnd, szBuf, APPLICATION, MB_OK | MB_ICONINFORMATION);
   } // one transfer --> display stats
 else 
  {
      sTC.dwMultiFileBlk += sTC.nCount;
      sTC.dwMultiFile++;
 }


return TRUE;
} // TransferOK
Ejemplo n.º 29
0
static char *dss_fingerprint(void *key)
{
    struct dss_key *dss = (struct dss_key *) key;
    struct MD5Context md5c;
    unsigned char digest[16], lenbuf[4];
    char buffer[16 * 3 + 40];
    char *ret;
    int numlen, i;

    MD5Init(&md5c);
    MD5Update(&md5c, (unsigned char *)"\0\0\0\7ssh-dss", 11);

#define ADD_BIGNUM(bignum) \
    numlen = (bignum_bitcount(bignum)+8)/8; \
    PUT_32BIT(lenbuf, numlen); MD5Update(&md5c, lenbuf, 4); \
    for (i = numlen; i-- ;) { \
        unsigned char c = bignum_byte(bignum, i); \
        MD5Update(&md5c, &c, 1); \
    }
    ADD_BIGNUM(dss->p);
    ADD_BIGNUM(dss->q);
    ADD_BIGNUM(dss->g);
    ADD_BIGNUM(dss->y);
#undef ADD_BIGNUM

    MD5Final(digest, &md5c);

    sprintf(buffer, "ssh-dss %d ", bignum_bitcount(dss->p));
    for (i = 0; i < 16; i++)
	sprintf(buffer + strlen(buffer), "%s%02x", i ? ":" : "",
		digest[i]);
    ret = snewn(strlen(buffer) + 1, char);
    if (ret)
	strcpy(ret, buffer);
    return ret;
}
Ejemplo n.º 30
0
int main(int argc, char *argv[])
{
	int i;

	MD5_CTX md5;

	// privide _encrypt_
	for (i = 0; i < N; i++)
		encrypt[i] = 'a';
	encrypt[N] = '\0';

	MD5Init(&md5);
	MD5Update(&md5, encrypt, strlen((char *)encrypt));
	MD5Final(&md5, decrypt);

	printf("%s\n", encrypt);
//	printf("%s\n", decrypt);
	for (i = 0; i < 16; i++)
		printf("%02x", decrypt[i]);

	printf("\n");

	return 0;
}