Skip to contentSkip to conversation

Crypto Review

PATCH Michael Gorven 3 participants 10 messages Aug 17, 2009 – Aug 18, 2009

lore
Share & tools
lore
#0 lore raw

Hi

I posted my copyright assignment last weekend, so hopefully that will arrive at the FSF soon. In the meantime I have attached some code for review. These are the crypto module which manages ciphers and hashes, the SHA1 hash module, and the AES cipher module.

The full code is available in a Bazaar repository[1], and I can provide a diff or tarball of everything if preferred.

Michael

[1] http://michael.gorven.za.net/bzr/grub/luks

Signature · 3 lines
http://michael.gorven.za.net
PGP Key ID 1E016BE8
S/MIME Key ID AAF09E0E

=== modified file 'conf/common.rmk'

common.rmk +6 -0
@@ -617,3 +617,9 @@
 setjmp_mod_SOURCES = lib/$(target_cpu)/setjmp.S
 setjmp_mod_ASFLAGS = $(COMMON_ASFLAGS)
 setjmp_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+# For crypto.mod
+pkglib_MODULES += crypto.mod
+crypto_mod_SOURCES = crypto/crypto.c
+crypto_mod_CFLAGS = $(COMMON_CFLAGS)
+crypto_mod_LDFLAGS = $(COMMON_LDFLAGS)

=== added directory 'crypto'
=== added file 'crypto/crypto.c'

crypto.c +389 -0

389 lines not on this page · raw message

=== added file 'include/grub/crypto.h'

grub/crypto.h +137 -0

137 lines not on this page · raw message

=== modified file 'conf/common.rmk'

common.rmk +6 -0
@@ -653,3 +653,9 @@
 sha512_mod_SOURCES = crypto/sha512.c
 sha512_mod_CFLAGS = $(COMMON_CFLAGS)
 sha512_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+# For aes.mod
+pkglib_MODULES += aes.mod
+aes_mod_SOURCES = crypto/aes.c
+aes_mod_CFLAGS = $(COMMON_CFLAGS)
+aes_mod_LDFLAGS = $(COMMON_LDFLAGS)

=== added file 'crypto/aes.c'

aes.c +762 -0

762 lines not on this page · raw message

=== added file 'crypto/rijndael-tables.h'

rijndael-tables.h +1687 -0

1,687 lines not on this page · raw message

=== modified file 'conf/common.rmk'

common.rmk +6 -0
@@ -635,3 +635,9 @@
 md5_mod_SOURCES = crypto/md5.c
 md5_mod_CFLAGS = $(COMMON_CFLAGS)
 md5_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+# For sha1.mod
+pkglib_MODULES += sha1.mod
+sha1_mod_SOURCES = crypto/sha1.c
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

=== added file 'crypto/sha1.c'

sha1.c +371 -0

371 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.

#1 lore raw
Quoted 3 lines · Michael Gorven

Hi

I posted my copyright assignment last weekend,

Nice.

Quoted 7 lines

so hopefully that will arrive
at the FSF soon. In the meantime I have attached some code for review. These are the crypto module which manages ciphers and hashes, the SHA1 hash module, and the AES cipher module.

The full code is available in a Bazaar repository[1], and I can provide a diff or tarball of everything if preferred.

Diff would be nice. Because not all developpers (including me) are familiar with bzr and it would take time for me to find out how to request specifically the patch I want to review. Additionally not posting diff makes inline reply impossible. It's fine to ask people to test your bzr but for review patch is prefered.
BTW I have xts support ;)

Quoted 16 lines

Michael

[1] http://michael.gorven.za.net/bzr/grub/luks

--
http://michael.gorven.za.net
PGP Key ID 1E016BE8
S/MIME Key ID AAF09E0E

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 4 lines
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
#4 lore raw
In reply to Michael Gorven
Quoted 1 line

+#define MAX(a, b) (a > b ? a : b)

Dangerous. Use ((a)>(b)?(a):(b))

Quoted 1 line

+ grub_printf("%c%c", hexchars[(buffer[i]>>4)&0xF], hexchars[buffer[i]&0xF] );

Use %02x instead of ad-hoc code. Where is print_buffer used at all? Perhaps grub_printf or grub_dprintf will be better?

crypto.c line 54

Quoted 5 lines
crypto.c +5 -0
+struct cipher_list
+{
+  grub_cipher_t cipher;
+  struct cipher_list *next;
+};

For the reasons of compactness can you reuse list functions from list.h?

crypto.c line 94

Quoted 3 lines
crypto.c +3 -0
+  if (cipher == NULL)
+    {
+      const char *errstr = "Illegal cipher type";

You can use the construction like
switch ()
case ...:
return ...;
case ...:
return ...;
which is more readable imho
Can you move 'hash' command to a separate module (it's not useful to embed in core.img in many cases)
Cipher interface looks similar to libgcrypt but not hashes. Is it possible to have an interface similar to libgcrypt? We don't have to replicate the interface. libgcrypt has goals of speed and we have goals of size but if libgcrypt-like interface is as small as custom one I would prefer libgcrypt-like for maintainance reasons.

Quoted 11 lines

--
http://michael.gorven.za.net
PGP Key ID 1E016BE8
S/MIME Key ID AAF09E0E

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 4 lines
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
#2 lore raw
In reply to Vladimir 'phcoder' Serbinenko
Quoted 5 lines · On Monday 17 August 2009 18:07:07 Vladimir 'phcoder' Serbinenko wrote:

Diff would be nice. Because not all developpers (including me) are familiar with bzr and it would take time for me to find out how to request specifically the patch I want to review. Additionally not posting diff makes inline reply impossible. It's fine to ask people to test your bzr but for review patch is prefered.

I attached diffs for three of the modules, since comments on the cipher/hash interface and style will affect all the modules and so I didn't see much point in reviewing all of them right now. If you'd like a diff of everything I can do that though.

Michael

Signature · 3 lines
http://michael.gorven.za.net
PGP Key ID 1E016BE8
S/MIME Key ID AAF09E0E
#5 lore raw
In reply to Michael Gorven

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 2 lines

[1] http://michael.gorven.za.net/bzr/grub/luks

I have a stupid question .... what's the difference between the tip in your Mercurial repository[1] and the head in your Bazaar repository[2]?

[1] http://michael.gorven.za.net/hg/grub/luks/
[2] http://michael.gorven.za.net/bzr/grub/luks/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkqJkCsACgkQBV7eXqefhqgN8gCgrskiR4x/eZnS4gmhAqk0kENi 6C8AnAp3ZXGVbbEl/ujBd4MQ+KNDm9wC
=OUux
-----END PGP SIGNATURE-----

#3 lore raw
In reply to Michael Gorven
Quoted 10 lines · Michael Gorven
Quoted 5 lines · On Monday 17 August 2009 18:07:07 Vladimir 'phcoder' Serbinenko wrote:

Diff would be nice. Because not all developpers (including me) are familiar with bzr and it would take time for me to find out how to request specifically the patch I want to review. Additionally not posting diff makes inline reply impossible. It's fine to ask people to test your bzr but for review patch is prefered.

I attached diffs for three of the modules, since comments on the cipher/hash interface and style will affect all the modules and so I didn't see much point in reviewing all of them right now.

I agree. Just when I first read your mail I was under impression you attached no patches and only then I noticed attached files. Sorry for that

Quoted 16 lines

If you'd like a diff of everything
I can do that though.

Michael

--
http://michael.gorven.za.net
PGP Key ID 1E016BE8
S/MIME Key ID AAF09E0E

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 4 lines
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
#6 lore raw
In reply to Duboucher Thomas
Quoted 2 lines · On Monday 17 August 2009 19:15:23 Duboucher Thomas wrote:

I have a stupid question .... what's the difference between the tip in your Mercurial repository[1] and the head in your Bazaar repository[2]?

The Mercurial repo is deprecated. I'll actually remove it.

Signature · 3 lines
http://michael.gorven.za.net
PGP Key ID 1E016BE8
S/MIME Key ID AAF09E0E
#7 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 6 lines · Michael Gorven
Quoted 2 lines · On Monday 17 August 2009 19:15:23 Duboucher Thomas wrote:

I have a stupid question .... what's the difference between the tip in your Mercurial repository[1] and the head in your Bazaar repository[2]?

The Mercurial repo is deprecated. I'll actually remove it.

Actually, I wanted to know if the code in the mercurial repository was
the same as the one in the Bazaar repository. The reason is I made previously a patch from hg and I do not have what I need to diff the two repositories. :|
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkqK1FcACgkQBV7eXqefhqhDOgCaAqyFSVBTMD8liIKRGCLnAhY4 NCkAnRTMWeD6641569P5zHldyEaiCV+2
=KSKH
-----END PGP SIGNATURE-----

#8 lore raw
Quoted 4 lines · On Tuesday 18 August 2009 18:18:31 Duboucher Thomas wrote:

Actually, I wanted to know if the code in the mercurial repository was the same as the one in the Bazaar repository. The reason is I made previously a patch from hg and I do not have what I need to diff the two repositories. :|

The Mercurial code is not up to date with the GRUB2 trunk, but is only missing a minor addition to the new crypto code. I've created a tarball[1] of the latest code if that helps.

Michael

[1] http://michael.gorven.za.net/files/grub2-luks-bzr1636.tar.bz2

Signature · 3 lines
http://michael.gorven.za.net
PGP Key ID 1E016BE8
S/MIME Key ID AAF09E0E
#9 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 4 lines

The Mercurial code is not up to date with the GRUB2 trunk, but is only missing a minor addition to the new crypto code. I've created a tarball[1] of the latest code if that helps.

Thanks a lot! I'll check that out tomorrow.

I've worked with your patch for a few days now, and it worked very well
so far. I used sha256 and ripemd160 functions alone, and also a simple LUKS setup, all without any trouble at all.
However, my compiler complains with a lot of warnings, mostly from
signdness differences between types and unused results. Is it a normal behaviour?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkqLEM4ACgkQBV7eXqefhqjASQCgl6L2o8anRT/JX2JcZf65oXpR gSUAn2zLYTOA+KNGBpf6BAPC3hlDSZHm
=K+dr
-----END PGP SIGNATURE-----

crypto/crypto.c:40: warning: no previous prototype for �print_buffer�
crypto/crypto.c: In function �print_buffer�:
crypto/crypto.c:43: warning: format not a string literal and no format arguments crypto/crypto.c: In function �grub_crypto_encrypt�:
crypto/crypto.c:207: warning: unused parameter �outsize�
crypto/crypto.c: In function �grub_crypto_decrypt�:
crypto/crypto.c:231: warning: unused parameter �outsize�
crypto/crypto.c: In function �grub_cmd_hash�:
crypto/crypto.c:364: warning: comparison between signed and unsigned
crypto/crypto.c:346: warning: unused parameter �state�
crypto/crypto.c: In function �grub_mod_init�:
crypto/crypto.c:379: warning: passing argument 2 of �grub_register_command� from incompatible pointer type crypto/crypto.c: In function �grub_mod_fini�:
crypto/crypto.c:386: warning: passing argument 1 of �grub_unregister_command� from incompatible pointer type crypto/ripemd160.c: In function �grub_hash_rmd160_fn�:
crypto/ripemd160.c:539: warning: unused parameter �params�
crypto/md5.c: In function �grub_hash_md5_fn�:
crypto/md5.c:326: warning: unused parameter �params�
crypto/sha1.c: In function �grub_hash_sha1_fn�:
crypto/sha1.c:337: warning: unused parameter �params�
crypto/sha256.c: In function �grub_hash_sha256_fn�:
crypto/sha256.c:291: warning: unused parameter �params�
crypto/sha512.c: In function �grub_hash_sha512_fn�:
crypto/sha512.c:344: warning: unused parameter �params�
crypto/aes.c: In function �do_setkey�:
crypto/aes.c:162: warning: comparison between signed and unsigned
crypto/aes.c: In function �grub_cipher_aes_decrypt_block�:
crypto/aes.c:718: warning: passing argument 2 of �rijndael_decrypt� from incompatible pointer type crypto/aes.c:718: warning: passing argument 3 of �rijndael_decrypt� from incompatible pointer type crypto/aes.c: In function �grub_cipher_aes_encrypt_block�:
crypto/aes.c:725: warning: passing argument 2 of �rijndael_encrypt� from incompatible pointer type crypto/aes.c:725: warning: passing argument 3 of �rijndael_encrypt� from incompatible pointer type crypto/cast5.c: In function �grub_cipher_cast5_set_key�:
crypto/cast5.c:634: warning: pointer targets in passing argument 2 of �cast_setkey� differ in signedness crypto/cast5.c: In function �grub_cipher_cast5_decrypt_block�:
crypto/cast5.c:641: warning: pointer targets in passing argument 2 of �decrypt_block� differ in signedness crypto/cast5.c:641: warning: pointer targets in passing argument 3 of �decrypt_block� differ in signedness crypto/cast5.c: In function �grub_cipher_cast5_encrypt_block�:
crypto/cast5.c:648: warning: pointer targets in passing argument 2 of �encrypt_block� differ in signedness crypto/cast5.c:648: warning: pointer targets in passing argument 3 of �encrypt_block� differ in signedness crypto/serpent.c: In function �serpent_key_prepare�:
crypto/serpent.c:583: warning: comparison between signed and unsigned
crypto/twofish.c:704: warning: return type defaults to �int�
crypto/twofish.c:703: warning: no previous prototype for �twofish_setkey�
crypto/twofish.c: In function �grub_cipher_twofish_set_key�:
crypto/twofish.c:1049: warning: pointer targets in passing argument 2 of �twofish_setkey� differ in signedness crypto/twofish.c: In function �grub_cipher_twofish_decrypt_block�:
crypto/twofish.c:1056: warning: pointer targets in passing argument 2 of �twofish_decrypt� differ in signedness crypto/twofish.c:1056: warning: pointer targets in passing argument 3 of �twofish_decrypt� differ in signedness crypto/twofish.c: In function �grub_cipher_twofish_encrypt_block�:
crypto/twofish.c:1063: warning: pointer targets in passing argument 2 of �twofish_encrypt� differ in signedness crypto/twofish.c:1063: warning: pointer targets in passing argument 3 of �twofish_encrypt� differ in signedness disk/luks.c: In function �grub_read_password�:
disk/luks.c:122: warning: format not a string literal and no format arguments disk/luks.c:126: warning: comparison between signed and unsigned
disk/luks.c: In function �print_buffer�:
disk/luks.c:153: warning: format not a string literal and no format arguments
disk/luks.c: In function �luks_decrypt�:
disk/luks.c:397: warning: pointer targets in passing argument 2 of �grub_crypto_encrypt� differ in signedness disk/luks.c:397: warning: pointer targets in passing argument 3 of �grub_crypto_encrypt� differ in signedness disk/luks.c: In function �grub_luks_open�:
disk/luks.c:507: warning: implicit declaration of function �grub_env_get�
disk/luks.c:507: warning: assignment makes pointer from integer without a cast disk/luks.c:507: warning: suggest parentheses around assignment used as truth value disk/luks.c: In function �grub_cmd_devmap�:
disk/luks.c:947: warning: implicit declaration of function �grub_cmdline_get�
disk/luks.c: At top level:
disk/luks.c:977: warning: function declaration isn�t a prototype
disk/luks.c:853: warning: �grub_cmd_devmap� defined but not used
disk/devmapper.c: In function �grub_mod_init�:
disk/devmapper.c:407: warning: passing argument 2 of �grub_register_command� from incompatible pointer type disk/devmapper.c: In function �grub_mod_fini�:
disk/devmapper.c:413: warning: passing argument 1 of �grub_unregister_command� from incompatible pointer type