Jump to content

Localized key with MD5


Recommended Posts

I'm trying to developed in LabView the algorithm used to generete localized key with MD5 defined in the rfc2574.

maybe sombody already did it, is this code already available somewhere?

 

thank you

A.2.1.  Password to Key Sample Code for MD5void password_to_key_md5(   u_char *password,    /* IN */   u_int   passwordlen, /* IN */   u_char *engineID,    /* IN  - pointer to snmpEngineID  */   u_int   engineLength,/* IN  - length of snmpEngineID */   u_char *key)         /* OUT - pointer to caller 16-octet buffer */{   MD5_CTX     MD;   u_char     *cp, password_buf[64];   u_long      password_index = 0;   u_long      count = 0, i;   MD5Init (&MD);   /* initialize MD5 */   /**********************************************/   /* Use while loop until we've done 1 Megabyte */   /**********************************************/   while (count < 1048576) {      cp = password_buf;      for (i = 0; i < 64; i++) {          /*************************************************/          /* Take the next octet of the password, wrapping */          /* to the beginning of the password as necessary.*/          /*************************************************/          *cp++ = password[password_index++ % passwordlen];      }      MD5Update (&MD, password_buf, 64);      count += 64;   }   MD5Final (key, &MD);          /* tell MD5 we're done */   /*****************************************************/   /* Now localize the key with the engineID and pass   */   /* through MD5 to produce final key                  */   /* May want to ensure that engineLength <= 32,       */   /* otherwise need to use a buffer larger than 64     */   /*****************************************************/   memcpy(password_buf, key, 16);   memcpy(password_buf+16, engineID, engineLength);   memcpy(password_buf+16+engineLength, key, 16);   MD5Init(&MD);   MD5Update(&MD, password_buf, 32+engineLength);   MD5Final(key, &MD);   return;}
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.