|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
CWE-323: Reusing a Nonce, Key Pair in Encryption
Example 1 (Bad Code) Example
Language: C #include <openssl/sha.h> #include <stdio.h> #include <string.h> #include <memory.h> int main(){ char *paragraph = NULL;
char *data = NULL;
char *nonce = "bad";
char *password = "secret";
parsize=strlen(nonce)+strlen(password);
paragraph=(char*)malloc(para_size);
strncpy(paragraph,nonce,strlen(nonce));
strcpy(paragraph,password,strlen(password));
data=(unsigned char*)malloc(20);
SHA1((const unsigned char*)paragraph,parsize,(unsigned
char*)data);
free(paragraph);
free(data);
//Do something with data//
return 0;
} (Bad Code) Example
Language: C++ String command = new String("some command to execute"); MessageDigest nonce = MessageDigest.getInstance("SHA"); nonce.update(String.valueOf("bad nonce")); byte[] nonce = nonce.digest(); MessageDigest password = MessageDigest.getInstance("SHA"); password.update(nonce + "secretPassword"); byte[] digest = password.digest(); //do something with digest//
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Page Last Updated:
September 12, 2011
|
|
CWE is a Software Assurance strategic initiative co-sponsored by the National Cyber Security Division of the U.S. Department of Homeland Security. This Web site is sponsored and managed by The MITRE Corporation to enable stakeholder collaboration. Copyright © 2006-2012, The MITRE Corporation. CWE, CWSS, CWRAF, and the CWE logo are trademarks of The MITRE Corporation. Contact cwe@mitre.org for more information. |
|||



