Use uint64_t and avoid down casting as much as possible.

Change-Id: I231d1b3a059907c3806feced7e1b8f1c06575ba5

BUG=chromeos-partner:2912
TEST=make clean all && make runtests

Review URL: http://codereview.chromium.org/6733018
This commit is contained in:
Gaurav Shah
2011-03-25 14:02:13 -07:00
parent 2c7213d4dc
commit d583a30a7c
4 changed files with 16 additions and 16 deletions

View File

@@ -75,7 +75,7 @@ int RSAVerifyBinaryWithDigest_f(const uint8_t* key_blob,
* *
* Returns 1 on success, 0 on failure. * Returns 1 on success, 0 on failure.
*/ */
int RSAProcessedKeySize(unsigned int algorithm, int* out_size); uint64_t RSAProcessedKeySize(uint64_t algorithm, uint64_t* out_size);
/* Allocate a new RSAPublicKey structure and initialize its pointer fields to /* Allocate a new RSAPublicKey structure and initialize its pointer fields to
* NULL */ * NULL */
@@ -89,7 +89,7 @@ void RSAPublicKeyFree(RSAPublicKey* key);
* *
* Caller owns the returned key and must free it. * Caller owns the returned key and must free it.
*/ */
RSAPublicKey* RSAPublicKeyFromBuf(const uint8_t* buf, int len); RSAPublicKey* RSAPublicKeyFromBuf(const uint8_t* buf, uint64_t len);
#endif /* VBOOT_REFERENCE_RSA_H_ */ #endif /* VBOOT_REFERENCE_RSA_H_ */

View File

@@ -9,9 +9,9 @@
#include "stateful_util.h" #include "stateful_util.h"
#include "utility.h" #include "utility.h"
int RSAProcessedKeySize(unsigned int algorithm, int* out_size) { uint64_t RSAProcessedKeySize(uint64_t algorithm, uint64_t* out_size) {
int key_len; /* Key length in bytes. */ uint64_t key_len; /* Key length in bytes. */
if (algorithm < (unsigned int)kNumAlgorithms) { if (algorithm < kNumAlgorithms) {
key_len = siglen_map[algorithm]; key_len = siglen_map[algorithm];
/* Total size needed by a RSAPublicKey structure is = /* Total size needed by a RSAPublicKey structure is =
* 2 * key_len bytes for the n and rr arrays * 2 * key_len bytes for the n and rr arrays
@@ -38,10 +38,10 @@ void RSAPublicKeyFree(RSAPublicKey* key) {
} }
} }
RSAPublicKey* RSAPublicKeyFromBuf(const uint8_t* buf, int len) { RSAPublicKey* RSAPublicKeyFromBuf(const uint8_t* buf, uint64_t len) {
RSAPublicKey* key = RSAPublicKeyNew(); RSAPublicKey* key = RSAPublicKeyNew();
MemcpyState st; MemcpyState st;
int key_len; uint64_t key_len;
st.remaining_buf = (uint8_t*) buf; st.remaining_buf = (uint8_t*) buf;
st.remaining_len = len; st.remaining_len = len;
@@ -81,7 +81,7 @@ int RSAVerifyBinary_f(const uint8_t* key_blob,
unsigned int algorithm) { unsigned int algorithm) {
RSAPublicKey* verification_key = NULL; RSAPublicKey* verification_key = NULL;
uint8_t* digest = NULL; uint8_t* digest = NULL;
int key_size; uint64_t key_size;
int sig_size; int sig_size;
int success; int success;
@@ -120,7 +120,7 @@ int RSAVerifyBinaryWithDigest_f(const uint8_t* key_blob,
const uint8_t* sig, const uint8_t* sig,
unsigned int algorithm) { unsigned int algorithm) {
RSAPublicKey* verification_key = NULL; RSAPublicKey* verification_key = NULL;
int key_size; uint64_t key_size;
int sig_size; int sig_size;
int success; int success;

View File

@@ -115,23 +115,23 @@ int PublicKeyCopy(VbPublicKey* dest, const VbPublicKey* src) {
RSAPublicKey* PublicKeyToRSA(const VbPublicKey* key) { RSAPublicKey* PublicKeyToRSA(const VbPublicKey* key) {
RSAPublicKey *rsa; RSAPublicKey *rsa;
int key_size; uint64_t key_size;
if (kNumAlgorithms <= key->algorithm) { if (kNumAlgorithms <= key->algorithm) {
VBDEBUG(("Invalid algorithm.\n")); VBDEBUG(("Invalid algorithm.\n"));
return NULL; return NULL;
} }
if (!RSAProcessedKeySize((int)key->algorithm, &key_size) || if (!RSAProcessedKeySize(key->algorithm, &key_size) ||
key_size != (int)key->key_size) { key_size != key->key_size) {
VBDEBUG(("Wrong key size for algorithm\n")); VBDEBUG(("Wrong key size for algorithm\n"));
return NULL; return NULL;
} }
rsa = RSAPublicKeyFromBuf(GetPublicKeyDataC(key), (int)key->key_size); rsa = RSAPublicKeyFromBuf(GetPublicKeyDataC(key), key->key_size);
if (!rsa) if (!rsa)
return NULL; return NULL;
rsa->algorithm = (int)key->algorithm; rsa->algorithm = (unsigned int)key->algorithm;
return rsa; return rsa;
} }

View File

@@ -167,7 +167,7 @@ VbPublicKey* PublicKeyReadKeyb(const char* filename, uint64_t algorithm,
VbPublicKey* key; VbPublicKey* key;
uint8_t* key_data; uint8_t* key_data;
uint64_t key_size; uint64_t key_size;
int expected_key_size; uint64_t expected_key_size;
if (algorithm >= kNumAlgorithms) { if (algorithm >= kNumAlgorithms) {
VBDEBUG(("PublicKeyReadKeyb() called with invalid algorithm!\n")); VBDEBUG(("PublicKeyReadKeyb() called with invalid algorithm!\n"));
@@ -205,7 +205,7 @@ VbPublicKey* PublicKeyReadKeyb(const char* filename, uint64_t algorithm,
VbPublicKey* PublicKeyRead(const char* filename) { VbPublicKey* PublicKeyRead(const char* filename) {
VbPublicKey* key; VbPublicKey* key;
uint64_t file_size; uint64_t file_size;
int key_size; uint64_t key_size;
key = (VbPublicKey*)ReadFile(filename, &file_size); key = (VbPublicKey*)ReadFile(filename, &file_size);
if (!key) if (!key)