Repository navigation
Conversation
sjaeckel
left a comment
There was a problem hiding this comment.
Basically LGTM, just some ideas which don't necessarily need to be followed up if you disagree, besides the change to use struct password_ctx which should be implemented IMO.
| int pbes2_encrypt( unsigned char *out, unsigned long *outlen, | ||
| const unsigned char *in, unsigned long inlen, | ||
| const unsigned char *pw, unsigned long pwlen, | ||
| const pbes2_enc_params *params, | ||
| prng_state *prng, int wprng); |
There was a problem hiding this comment.
Do we need this as a public API? I don't think so!?
We can still document the type here, that is good!
|
|
||
| int pem_encode_pkcs_filehandle(FILE *f, int which, const ltc_pka_key *key, | ||
| const pem_encode_opts *opts, | ||
| prng_state *prng, int wprng); |
|
|
||
| ivlen = cipher_descriptor[cid].block_length; | ||
| if (keylen > sizeof(key) || ivlen > sizeof(iv) || inlen > ULONG_MAX - ivlen) return CRYPT_INVALID_ARG; | ||
| ctlen = inlen + ivlen - (inlen % ivlen); /* PKCS#7 padding adds 1 to ivlen bytes */ |
There was a problem hiding this comment.
- Shouldn't
padding_pad()with*padded_length < lengthdo this calculation for you? - What is that comment about?
| if ((err = pka_key_export(*der, derlen, which, key)) != CRYPT_OK) { | ||
| zeromem(*der, len); | ||
| XFREE(*der); | ||
| *der = NULL; |
There was a problem hiding this comment.
Maybe add
| *der = NULL; | |
| *der = NULL; | |
| *derlen = 0; |
| /** PBES2 parameters, NULL for the defaults */ | ||
| const pbes2_enc_params *enc; |
There was a problem hiding this comment.
How about creating an intermediate union type and using that one here?
typedef union pem_enc_params {
const pbes2_enc_params *pbes2;
} pem_enc_params;
and add an entry to pem_encode_flags LTC_PEM_PBES2 = 0, since someone will come and wants to add other formats ... Maybe then also change LTC_PEM_CRLF = 8...
| /** Password, NULL writes the key unencrypted */ | ||
| const unsigned char *pw; | ||
| /** Length of the password, an empty password is refused */ | ||
| unsigned long pwlen; |
There was a problem hiding this comment.
Don't we want this interactive instead via struct password_ctx?
| } | ||
| } | ||
|
|
||
| b64len = 4 * ((bodylen + 2) / 3); |
There was a problem hiding this comment.
Maybe add the following to tomcrypt_private.h and also use it in s_base64_encode_internal()?
#define ltc_base64_encoded_len(len) (4 * (((len) + 2) / 3))
Adds the write side for PKCS#8 keys, which so far could only be read.
pbes2_encrypt()- encrypts aPrivateKeyInfointo anEncryptedPrivateKeyInfo(PBES2 with PBKDF2 and AES or 3DES in CBC mode)pka_key_export()- PKCS#8 or SubjectPublicKeyInfo export of anyltc_pka_keypem_encode_pkcs()+pem_encode_pkcs_filehandle()- PEM output according to RFC 7468 (PRIVATE KEY,ENCRYPTED PRIVATE KEY,PUBLIC KEY)Three commits fix bugs that are already in
developand are not directly related to PBES2. They were found while working on this: