<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Hi Michi,<br>
<br>
<div class="moz-cite-prefix">On 14:42 Sun 15 June,
<a class="moz-txt-link-abbreviated" href="mailto:michi1@michaelblizek.twilightparadox.com">michi1@michaelblizek.twilightparadox.com</a> wrote:<br>
</div>
<blockquote cite="mid:20140615064208.GA4444@grml" type="cite">
<pre wrap="">Hi!
On 21:28 Sat 14 Jun , Freeman Zhang wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Hi list,
Recently I'm learning to use kernel crypto. I find some examples but
they are out of date.
I manage to write a test program, trying to use aes to encrypt 'buf'
,but something goes wrong:
struct scatterlist sg;
struct crypto_blkcipher *tfm;
struct blkcipher_desc desc;
unsigned char buf[10];
char *key = "00112233445566778899aabbccddeeff";
int keylen = 16;
memset(buf, 'A', 10);
tfm = crypto_alloc_blkcipher("ecb(aes)", 0, CRYPTO_ALG_ASYNC);
crypto_blkcipher_setkey(tfm,key,keylen);
desc.tfm = tfm;
desc.flags = 1;
sg_init_one(&sg, buf, 10);
crypto_blkcipher_encrypt(&desc, &sg, &sg, 10);
sg_set_buf(&sg, buf,10);
hexdump(buf,10);
The result of hexdump(buf) shows that 'buf' stay unchanged. What should
I do to encrypt the buffer?
</pre>
</blockquote>
<pre wrap="">
Crypto works differently that you probably think it does.
First of all, NEVER NEVER NEVER NEVER NEVER NEVER NEVER use ecb mode. Open
wikipedia to see why. This is one of the most basic mistakes you can make.
</pre>
</blockquote>
No one have told me that. I just pick up one mode randomly.
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
Thanks for the information. <br>
<blockquote cite="mid:20140615064208.GA4444@grml" type="cite">
<pre wrap="">
The reason why the you see plaintext is probably because the buffer size is
not a multiple of you aes block size (16 bytes). </pre>
</blockquote>
Yes, you're right. I'm glad that there is no more plaintext when I
simply modified the buffer size to 16.<br>
<blockquote cite="mid:20140615064208.GA4444@grml" type="cite">
<pre wrap="">But I must admit that leaving
the data unencrypted instead of e.g. zeroing it does not sound like a good api
design to me...</pre>
</blockquote>
<blockquote cite="mid:20140615064208.GA4444@grml" type="cite">
<pre wrap="">
        -Michi
</pre>
</blockquote>
I've checked something about ecb mode and cbc mode. I'm confused by
the iv. Is iv only for cbc mode?<br>
How can I set up and initiate iv in the kernel? I don't know where
to find an example about this, just try-and-error.<br>
<br>
<br>
Much thanks !<br>
<br>
Freeman<br>
</body>
</html>