asn: refactoring MakeAnyCert to reduce stack usage:

--- variable der moved to the heap (sizeof(DerCert) bytes saved)

asn: refactoring MakeCertReq to reduce stack usage:
--- variable der moved to the heap (sizeof(DerCert) bytes saved)
This commit is contained in:
Moisés Guimarães 2014-07-04 09:50:20 -03:00
parent 1739aea535
commit 85dcc8e5e2

View File

@ -5621,21 +5621,26 @@ static int MakeAnyCert(Cert* cert, byte* derBuffer, word32 derSz,
RsaKey* rsaKey, ecc_key* eccKey, RNG* rng,
const byte* ntruKey, word16 ntruSz)
{
DerCert der;
int ret;
DECLARE_VAR(DerCert, der);
if (eccKey)
cert->keyType = ECC_KEY;
cert->keyType = eccKey ? ECC_KEY : (rsaKey ? RSA_KEY : NTRU_KEY);
if (!CREATE_VAR(DerCert, der))
return MEMORY_E;
ret = EncodeCert(cert, der, rsaKey, eccKey, rng, ntruKey, ntruSz);
if (ret == 0) {
if (der->total + MAX_SEQ_SZ * 2 > (int)derSz)
ret = BUFFER_E;
else
cert->keyType = rsaKey ? RSA_KEY : NTRU_KEY;
ret = EncodeCert(cert, &der, rsaKey, eccKey, rng, ntruKey, ntruSz);
if (ret != 0)
ret = cert->bodySz = WriteCertBody(der, derBuffer);
}
DESTROY_VAR(der);
return ret;
if (der.total + MAX_SEQ_SZ * 2 > (int)derSz)
return BUFFER_E;
return cert->bodySz = WriteCertBody(&der, derBuffer);
}
@ -5831,18 +5836,26 @@ static int WriteCertReqBody(DerCert* der, byte* buffer)
int MakeCertReq(Cert* cert, byte* derBuffer, word32 derSz,
RsaKey* rsaKey, ecc_key* eccKey)
{
DerCert der;
int ret;
DECLARE_VAR(DerCert, der);
cert->keyType = eccKey ? ECC_KEY : RSA_KEY;
if (!CREATE_VAR(DerCert, der))
return MEMORY_E;
ret = EncodeCertReq(cert, der, rsaKey, eccKey);
if (ret == 0) {
if (der->total + MAX_SEQ_SZ * 2 > (int)derSz)
ret = BUFFER_E;
else
ret = cert->bodySz = WriteCertReqBody(der, derBuffer);
}
DESTROY_VAR(der);
cert->keyType = (eccKey != NULL) ? ECC_KEY : RSA_KEY;
ret = EncodeCertReq(cert, &der, rsaKey, eccKey);
if (ret != 0)
return ret;
if (der.total + MAX_SEQ_SZ * 2 > (int)derSz)
return BUFFER_E;
return cert->bodySz = WriteCertReqBody(&der, derBuffer);
}
#endif /* CYASSL_CERT_REQ */