Chromium Code Reviews| Index: mozilla/security/nss/lib/freebl/shvfy.c |
| =================================================================== |
| --- mozilla/security/nss/lib/freebl/shvfy.c (revision 164196) |
| +++ mozilla/security/nss/lib/freebl/shvfy.c (working copy) |
| @@ -15,6 +15,8 @@ |
| #include "seccomon.h" |
| #include "stdio.h" |
| #include "prmem.h" |
| +#include "hasht.h" |
| +#include "pqg.h" |
| /* |
| * Most modern version of Linux support a speed optimization scheme where an |
| @@ -314,7 +316,8 @@ |
| char *checkName = NULL; |
| PRFileDesc *checkFD = NULL; |
| PRFileDesc *shFD = NULL; |
| - SHA1Context *hashcx = NULL; |
| + void *hashcx = NULL; |
| + SECHashObject *hashObj = NULL; |
| SECItem signature = { 0, NULL, 0 }; |
| SECItem hash; |
| int bytesRead, offset; |
| @@ -328,7 +331,7 @@ |
| PRBool result = PR_FALSE; /* if anything goes wrong, |
| * the signature does not verify */ |
| unsigned char buf[4096]; |
| - unsigned char hashBuf[SHA1_LENGTH]; |
| + unsigned char hashBuf[HASH_LENGTH_MAX]; |
| PORT_Memset(&key,0,sizeof(key)); |
| hash.data = hashBuf; |
| @@ -403,6 +406,11 @@ |
| PR_Close(checkFD); |
| checkFD = NULL; |
| + hashObj = HASH_GetRawHashObject(PQG_GetHashType(&key.params)); |
| + if (hashObj == NULL) { |
| + goto loser; |
| + } |
| + |
| /* open our library file */ |
| #ifdef FREEBL_USE_PRELINK |
| shFD = bl_OpenUnPrelink(shName,&pid); |
| @@ -418,15 +426,15 @@ |
| } |
| /* hash our library file with SHA1 */ |
| - hashcx = SHA1_NewContext(); |
| + hashcx = hashObj->create(); |
| if (hashcx == NULL) { |
| goto loser; |
| } |
| - SHA1_Begin(hashcx); |
| + hashObj->begin(hashcx); |
| count = 0; |
| while ((bytesRead = PR_Read(shFD, buf, sizeof(buf))) > 0) { |
| - SHA1_Update(hashcx, buf, bytesRead); |
| + hashObj->update(hashcx, buf, bytesRead); |
| count += bytesRead; |
| } |
| #ifdef FREEBL_USE_PRELINK |
| @@ -436,7 +444,7 @@ |
| #endif |
| shFD = NULL; |
| - SHA1_End(hashcx, hash.data, &hash.len, hash.len); |
| + hashObj->end(hashcx, hash.data, &hash.len, hash.len); |
| /* verify the hash against the check file */ |
| @@ -480,7 +488,9 @@ |
| PR_Close(shFD); |
| } |
| if (hashcx != NULL) { |
| - SHA1_DestroyContext(hashcx,PR_TRUE); |
| + if (hashObj) { |
|
wtc
2012/11/07 22:12:33
This null test for hashObj seems unnecessary.
|
| + hashObj->destroy(hashcx,PR_TRUE); |
| + } |
| } |
| if (signature.data != NULL) { |
| PORT_Free(signature.data); |