<div dir="ltr"><div>Thanks Matt, it works fine now.<br></div><div><br></div><div><div><div dir="ltr" class="m_5176004497096198700gmail_signature" data-smartmail="gmail_signature">Regards,<br>Luís<br></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, May 17, 2018 at 10:09 AM Matt Caswell <<a href="mailto:matt@openssl.org" target="_blank">matt@openssl.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
On 16/05/18 18:55, Luís Martins wrote:<br>
> Hi,<br>
> <br>
>     I'm trying to use the EVP AES wrap implementations from openssl<br>
> (e.g. EVP_aes_128/192/256_wrap()) but I'm getting the following error in<br>
> EVP_EncryptInit_ex() f:<br>
>     error:0607B0AA:digital envelope routines:EVP_CipherInit_ex:wrap mode<br>
> not allowed<br>
>     I've search the documentation for examples or guidance but I<br>
> couldn't find anything related to this.<br>
>     Any experienced the same issue ?<br>
<br>
You need to enable wrap mode:<br>
<br>
EVP_CIPHER_CTX_set_flags(&ctx, EVP_CIPHER_CTX_FLAG_WRAP_ALLOW);<br>
<br>
The EVP encrypt routines set an expectation about how long the output<br>
might be for a given input:<br>
<br>
"EVP_EncryptUpdate() encrypts B<inl> bytes from the buffer B<in> and<br>
writes the encrypted version to B<out>. This function can be called<br>
multiple times to encrypt successive blocks of data. The amount<br>
of data written depends on the block alignment of the encrypted data:<br>
as a result the amount of data written may be anything from zero bytes<br>
to (inl + cipher_block_size - 1) so B<out> should contain sufficient<br>
room."<br>
<br>
The wrap modes do not obey this rule and may return more data, so you<br>
have to explicitly enable the mode to say that you are prepared for the<br>
output.<br>
<br>
Matt<br>
<br>
<br>
> <br>
>     My pseudo code is:<br>
> <br>
>         EVP_CIPHER_CTX ctx;<br>
>         EVP_CIPHER_CTX_init(&ctx);<br>
>         if (EVP_EncryptInit_ex(&ctx, EVP_aes_128_wrap(), 0,<br>
> keyEncriptionKey, iv) != 1)<br>
>              // process error<br>
>         if ( EVP_EncryptUpdate(&ctx, bufferOut, &processedSize,<br>
> plaintext, plaintextSize) != 1)<br>
>              // process error<br>
>         if (EVP_EncryptFinal_ex(&ctx, bufferOut + processedSize,<br>
> &tmpSize) != 1)<br>
>              // process error<br>
>         EVP_CIPHER_CTX_cleanup(&ctx);<br>
> <br>
> Regards,<br>
> Luís<br>
> <br>
> <br>
-- <br>
openssl-users mailing list<br>
To unsubscribe: <a href="https://mta.openssl.org/mailman/listinfo/openssl-users" rel="noreferrer" target="_blank">https://mta.openssl.org/mailman/listinfo/openssl-users</a><br>
</blockquote></div>