dm-crypt: add digest-based iv generation mode
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): Xine.LNX.4.44.0402231710390.21142-100000@thoron.boston.redhat.com
Quoted 2 lines · James Morris
As far as I can tell, you should just be adding a new wrapper interface like HMAC. Have a look at that code.
OK got the hint. ;)
I'll repeat my recommendation that OMACs be computed at the same time as encryption/decryption and not in a "two pass" approach like this. Ideally by passing two cipher contexts (one for encryption other for MACing) into functions like cbc_encrypt() - alas I'm too nervous with this API to implement that.
A Not-So-Ideal compromise would be using the same cipher context and storing the MAC in a new member of the cipher_tfm struct. This would require minimal amount of new code to test and will probably go faster as well.
The two patches are:
- http://jlcooke.ca/lkml/ctr_and_omac.patch
(added ctr to cipher.c and omac.c)
Using the init/update/final interface.
- http://jlcooke.ca/lkml/ctr_and_omac2.patch
(added ctr to cipher.c and integrated OMAC into all
existing modes of operation. If cipher_tfm.cit_omac!=NULL, OMAC is stored into cipher_tfm.cit_omac)
So in other words, current implementations using the CryptoAPI will not see performance change and no new .c files.
No OMAC:
tfm = crypto_alloc_tfm (algo, CRYPTO_TFM_MODE_CBC);
With OMAC:
tfm = crypto_alloc_tfm (algo, CRYPTO_TFM_MODE_CBC | CRYPTO_TFM_MODE_OMAC);
...
crypto_cipher_get_omac(tfm, omac_val, 128/8);
** J-L likes this one more! **Now implementing CCM mode (the final mode of operation specified for use with
AES by NIST) will be my next task. CCM is an IEEE standard and is going
through the motions of becoming a FIPS standard as well. Reference:
http://csrc.nist.gov/publications/drafts/Draft_SP_800-38C_9-04-2003.pdf
It's effectively CTR mode with a CBC MAC at the end of it. I'll start implementing it, but we'll hold off until the spec is out of draft.
JLC
ps. Will crypto_cipher_encrypt/crypto_cipher_decrypt *always* be called in onesies? I need to perform come final() code on the OMAC before it's ready to pass test vectors - how do I know when we're done?
Signature · 4 lines
http://www.certainkey.com Suite 4560 CTTC 1125 Colonel By Dr. Ottawa ON, K1S 5B6
Quoted 8 lines · Jean-Luc Cooke
The two patches are:
- http://jlcooke.ca/lkml/ctr_and_omac.patch
(added ctr tocipher.candomac.c)
Using theinit/update/finalinterface.
- http://jlcooke.ca/lkml/ctr_and_omac2.patch
(added ctr tocipher.cand integrated OMAC into all
existing modes of operation. If cipher_tfm.cit_omac!=NULL, OMAC is stored into cipher_tfm.cit_omac)
Looks good so far, although the duplicated scatterwalk code needs to be put into a separate file (e.g. scatterwalk.c).
Quoted 3 lines
ps. Will crypto_cipher_encrypt/crypto_cipher_decrypt *always* be called in onesies? I need to perform come
final()code on the OMAC before it's ready to pass test vectors - how do I know when we're done?
I don't understand what you mean here.
Thanks for all this work!
- James
Signature · 2 lines
James Morris <[email protected]>
Quoted 11 lines · James Morris
Quoted 8 lines · Jean-Luc Cooke
The two patches are:
- http://jlcooke.ca/lkml/ctr_and_omac.patch
(added ctr tocipher.candomac.c)
Using theinit/update/finalinterface.
- http://jlcooke.ca/lkml/ctr_and_omac2.patch
(added ctr tocipher.cand integrated OMAC into all
existing modes of operation. If cipher_tfm.cit_omac!=NULL, OMAC is stored into cipher_tfm.cit_omac)
Quoted 2 lines
Looks good so far, although the duplicated scatterwalk code needs to be put into a separate file (e.g.
scatterwalk.c).
OK. So which patch do you want? :) The omac.c with scatterwalk, or the cipher.c with omac performed in-place when needed?
Quoted 5 lines
Quoted 3 lines
ps. Will crypto_cipher_encrypt/crypto_cipher_decrypt *always* be called in onesies? I need to perform come
final()code on the OMAC before it's ready to pass test vectors - how do I know when we're done?I don't understand what you mean here.
finish_omac() needs to be called once all data is processed. How do I know for sure the caller is done with this cipher context instance?
For example:
loop {
/* get more data into sgin */
crypto_cipher_encrypt(tfm, sgout, sgin, len);
/* send our data out of sgout */ }
/* get the 128bit OMAC and send it since we're done with all our encryption */
And decryption:
loop {
/* get more data into sgin */
crypto_cipher_decrypt(tfm, sgout, sgin, len);
/* send our data out of sgout */ }
/* get the 128bit OMAC and compare it with transmitted OMAC since we're done
with all our decryption */
There is no explicit/implicit "crypto_cipher_encrypt_final()" to inform the API to finalise the OMAC.
Quoted 1 line
Thanks for all this work!
Gladly. Makes the beer at the pub go down with less guilt when I can say my name has appear in one more kernel source file. :)
JLC
Signature · 4 lines
http://www.certainkey.com Suite 4560 CTTC 1125 Colonel By Dr. Ottawa ON, K1S 5B6
Quoted 12 lines · Jean-Luc Cooke
Quoted 11 lines · James Morris
Quoted 8 lines · Jean-Luc Cooke
The two patches are:
- http://jlcooke.ca/lkml/ctr_and_omac.patch
(added ctr tocipher.candomac.c)
Using theinit/update/finalinterface.
- http://jlcooke.ca/lkml/ctr_and_omac2.patch
(added ctr tocipher.cand integrated OMAC into all
existing modes of operation. If cipher_tfm.cit_omac!=NULL, OMAC is stored into cipher_tfm.cit_omac)
Quoted 5 lines
Quoted 2 lines
Looks good so far, although the duplicated scatterwalk code needs to be put into a separate file (e.g.
scatterwalk.c).OK. So which patch do you want? :) The
omac.cwith scatterwalk, or thecipher.cwith omac performed in-place when needed?
I think the latter is preferrable. OMAC should probably be a config option as well.
Quoted 23 lines
Quoted 6 lines
Quoted 4 lines
ps. Will crypto_cipher_encrypt/crypto_cipher_decrypt *always* be called in onesies? I need to perform come
final()code on the OMAC before it's ready to pass test vectors - how do I know when we're done?I don't understand what you mean here.
finish_omac()needs to be called once all data is processed. How do I know for sure the caller is done with this cipher context instance?For example:
loop { /* get more data into sgin */ crypto_cipher_encrypt(tfm, sgout, sgin, len); /* send our data out of sgout */}
/* get the 128bit OMAC and send it since we're done with all our encryption */And decryption:
loop { /* get more data into sgin */ crypto_cipher_decrypt(tfm, sgout, sgin, len); /* send our data out of sgout */
Quoted 6 lines
}
/* get the 128bit OMAC and compare it with transmitted OMAC since we're done
with all our decryption */There is no explicit/implicit "
crypto_cipher_encrypt_final()" to inform the API to finalise the OMAC.
You could add something like crypto_cipher_omac_final(), to be used by the calling code once it needs the OMAC value, which then calls crypto_cipher_get_omac().
- James
Signature · 2 lines
James Morris <[email protected]>
Alright then.
http://jlcooke.ca/lkml/crypto_24feb2004.patch
Changes:
- Added CTR mode to cipher.c
- Fixed Bug where CTR wasn't getting allocated an IV
- Added config for OMAC option on encryption
- Moved scatterwalk stuff to scatterwalk.c added to makefile
- Removed kmalloc'd scratch space in hmac.c which caused a reported bug.
- kernel config defaults to build all the IPSec required algorithms as well as OMAC (OMAC is only computed if specified by caller)
JLC
Quoted 2 lines · James Morris
I think the latter is preferrable. OMAC should probably be a config option as well.
...
Quoted 3 lines
You could add something like
crypto_cipher_omac_final(), to be used by the calling code once it needs the OMAC value, which then callscrypto_cipher_get_omac().
Signature · 4 lines
http://www.certainkey.com Suite 4560 CTTC 1125 Colonel By Dr. Ottawa ON, K1S 5B6