--- a/source/rsa.c +++ b/source/rsa.c @@ -11,10 +11,10 @@ #include "rsa.h" #include "nn.h" -static int RSAPublicBlock PROTO_LIST +int RSAPublicBlock PROTO_LIST ((unsigned char *, unsigned int *, unsigned char *, unsigned int, R_RSA_PUBLIC_KEY *)); -static int RSAPrivateBlock PROTO_LIST +int RSAPrivateBlock PROTO_LIST ((unsigned char *, unsigned int *, unsigned char *, unsigned int, R_RSA_PRIVATE_KEY *)); @@ -33,6 +33,9 @@ unsigned char byte, pkcsBlock[MAX_RSA_MODULUS_LEN]; unsigned int i, modulusLen; + if (inputLen+3>MAX_RSA_MODULUS_LEN) return (RE_LEN); + if (publicKey->bits > MAX_RSA_MODULUS_BITS) return (RE_LEN); + modulusLen = (publicKey->bits + 7) / 8; if (inputLen + 11 > modulusLen) return (RE_LEN); @@ -78,6 +81,9 @@ unsigned char pkcsBlock[MAX_RSA_MODULUS_LEN]; unsigned int i, modulusLen, pkcsBlockLen; + if (inputLen>MAX_RSA_MODULUS_LEN) return (RE_LEN); + if (publicKey->bits > MAX_RSA_MODULUS_BITS) return (RE_LEN); + modulusLen = (publicKey->bits + 7) / 8; if (inputLen > modulusLen) return (RE_LEN); @@ -129,6 +135,9 @@ unsigned char pkcsBlock[MAX_RSA_MODULUS_LEN]; unsigned int i, modulusLen; + if (inputLen+3>MAX_RSA_MODULUS_LEN) return (RE_LEN); + if (privateKey->bits > MAX_RSA_MODULUS_BITS) return (RE_LEN); + modulusLen = (privateKey->bits + 7) / 8; if (inputLen + 11 > modulusLen) return (RE_LEN); @@ -168,6 +177,9 @@ unsigned char pkcsBlock[MAX_RSA_MODULUS_LEN]; unsigned int i, modulusLen, pkcsBlockLen; + if (inputLen>MAX_RSA_MODULUS_LEN) return (RE_LEN); + if (privateKey->bits > MAX_RSA_MODULUS_BITS) return (RE_LEN); + modulusLen = (privateKey->bits + 7) / 8; if (inputLen > modulusLen) return (RE_LEN); @@ -212,7 +224,7 @@ Assumes inputLen < length of modulus. Requires input < modulus. */ -static int RSAPublicBlock (output, outputLen, input, inputLen, publicKey) +int RSAPublicBlock (output, outputLen, input, inputLen, publicKey) unsigned char *output; /* output block */ unsigned int *outputLen; /* length of output block */ unsigned char *input; /* input block */ @@ -252,7 +264,7 @@ Assumes inputLen < length of modulus. Requires input < modulus. */ -static int RSAPrivateBlock (output, outputLen, input, inputLen, privateKey) +int RSAPrivateBlock (output, outputLen, input, inputLen, privateKey) unsigned char *output; /* output block */ unsigned int *outputLen; /* length of output block */ unsigned char *input; /* input block */