<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Texto de bal\00E3o Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";}
span.EstiloDeEmail17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.TextodebaloChar
        {mso-style-name:"Texto de bal\00E3o Char";
        mso-style-priority:99;
        mso-style-link:"Texto de bal\00E3o";
        font-family:"Tahoma","sans-serif";}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 3.0cm 70.85pt 3.0cm;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal>Hello,<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I’m trying to use the CFB1 mode for AES-128.<o:p></o:p></p><p class=MsoNormal>However I’m having a bit of trouble interpreting the encrypt output.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I believe the EVP_EnvryptUpdate should get the data length in BITS (other algorithms it should use in bytes). Is it correct?<o:p></o:p></p><p class=MsoNormal>How can I interpret the output correctly?<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I got my testing data from the FIPS140 test vectors.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Here is a quick code snippet to illustrate it:<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>#include <openssl/evp.h><o:p></o:p></p><p class=MsoNormal>#include <string.h><o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>int main() {<o:p></o:p></p><p class=MsoNormal>                unsigned char outbuf[1024];<o:p></o:p></p><p class=MsoNormal>                int outlen, tmplen;<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>                // From FIPS 140 test vectors (CFB1MCT128.rsp):<o:p></o:p></p><p class=MsoNormal>                //   COUNT = 0<o:p></o:p></p><p class=MsoNormal>                //   KEY = 6f219ca589944101d9b8d1997ec7f384<o:p></o:p></p><p class=MsoNormal>                //   IV = 00179d5c1f0436af09de22c09825b02d<o:p></o:p></p><p class=MsoNormal>                //   PLAINTEXT = 0<o:p></o:p></p><p class=MsoNormal>                //   CIPHERTEXT = 0<o:p></o:p></p><p class=MsoNormal>                unsigned char key[] = {0x6f, 0x21, 0x9c, 0xa5, 0x89, 0x94, 0x41, 0x01, 0xd9, 0xb8, 0xd1, 0x99, 0x7e, 0xc7, 0xf3, 0x84};<o:p></o:p></p><p class=MsoNormal>                unsigned char iv[] = {0x00, 0x17, 0x9d, 0x5c, 0x1f, 0x04, 0x36, 0xaf, 0x09, 0xde, 0x22, 0xc0, 0x98, 0x25, 0xb0, 0x2d};<o:p></o:p></p><p class=MsoNormal>                unsigned char intext[] = {0x00};<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>                EVP_CIPHER_CTX ctx;<o:p></o:p></p><p class=MsoNormal>                EVP_CIPHER_CTX_init(&ctx);<o:p></o:p></p><p class=MsoNormal>                EVP_EncryptInit_ex(&ctx, EVP_aes_128_cfb1(), NULL, key, iv);<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>                // EVP_EnvryptUpdate expects the number of bits or bytes in CFB1 mode?<o:p></o:p></p><p class=MsoNormal>                int datalen = 1; <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>                if (!EVP_EncryptUpdate(&ctx, outbuf, &outlen, intext, datalen)) return 1;<o:p></o:p></p><p class=MsoNormal>                if (!EVP_EncryptFinal_ex(&ctx, outbuf + outlen, &tmplen)) return 1;<o:p></o:p></p><p class=MsoNormal>                outlen += tmplen;<o:p></o:p></p><p class=MsoNormal>                EVP_CIPHER_CTX_cleanup(&ctx);<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>                for (int ii = 0; ii < outlen; ++ii) printf("%02x", outbut[ii]);<o:p></o:p></p><p class=MsoNormal>                printf("\n");<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>                // outbuf should contain CIPHERTEXT. However, it contains one single byte: 0x47 (71 decimal).<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>                return 0;<o:p></o:p></p><p class=MsoNormal>}<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Thanks very much.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Best,<o:p></o:p></p><p class=MsoNormal>Marcus<o:p></o:p></p></div></body></html>