From a4bafc47107165a839d6aec22e4cef1724785914 Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Tue, 10 Nov 2009 20:51:22 +0100 Subject: [PATCH] First working cipher import --- import_gcry.py | 90 +++++++++++++++++++-- include/grub/{gcry_wrap.h => cipher_wrap.h} | 13 +++ include/grub/crypto.h | 1 + 3 files changed, 99 insertions(+), 5 deletions(-) rename include/grub/{gcry_wrap.h => cipher_wrap.h} (92%) diff --git a/import_gcry.py b/import_gcry.py index cc06142e6..9a53a356a 100644 --- a/import_gcry.py +++ b/import_gcry.py @@ -10,10 +10,17 @@ indir = sys.argv[1] outdir = sys.argv[2] basedir = os.path.join (outdir, "gcry") -os.makedirs (basedir) +try: + os.makedirs (basedir) +except: + print ("WARNING: %s already exists" % basedir) cipher_dir_in = os.path.join (indir, "cipher") cipher_dir_out = os.path.join (basedir, "cipher") -os.makedirs (cipher_dir_out) +try: + os.makedirs (cipher_dir_out) +except: + print ("WARNING: %s already exists" % cipher_dir_out) + cipher_files = os.listdir (cipher_dir_in) conf = open (os.path.join (outdir, "conf", "gcry.rmk"), "w") conf.write ("# -*- makefile -*-\n\n") @@ -34,7 +41,33 @@ for cipher_file in cipher_files: fw.write (" import_gcry.py. Please don't modify it */\n"); ciphernames = [] mdnames = [] + hold = False + skip = False + skip2 = False for line in f: + if skip: + if line[0] == "}": + skip = False + continue + if skip2: + if not re.search (" *};", line) is None: + skip2 = False + continue + if hold: + hold = False + # We're optimising for size. + elif not re.match ("(run_selftests|selftest|_gcry_aes_c.._..c|_gcry_[a-z0-9]*_hash_buffer)", line) is None: + skip = True + fname = re.match ("[a-zA-Z0-9_]*", line).group () + chmsg = "(%s): Removed." % fname + if nch: + chlognew = "%s\n %s" % (chlognew, chmsg) + else: + chlognew = "%s %s" % (chlognew, chmsg) + nch = True + continue + else: + fw.write (holdline) m = re.match ("#include <.*>", line) if not m is None: chmsg = "Removed including of %s" % \ @@ -55,6 +88,46 @@ for cipher_file in cipher_files: mdname = line [len ("gcry_md_spec_t"):].strip () mdname = re.match("[a-zA-Z0-9_]*",mdname).group () mdnames.append (mdname) + m = re.match ("static const char \*selftest.*;$", line) + if not m is None: + fname = line[len ("static const char \*"):] + fname = re.match ("[a-zA-Z0-9_]*", fname).group () + chmsg = "(%s): Removed declaration." % fname + if nch: + chlognew = "%s\n %s" % (chlognew, chmsg) + else: + chlognew = "%s %s" % (chlognew, chmsg) + nch = True + continue + m = re.match ("(static const char( |)\*|static gpg_err_code_t|void)$", line) + if not m is None: + hold = True + holdline = line + continue + m = re.match ("cipher_extra_spec_t", line) + if isc and not m is None: + skip2 = True + fname = line[len ("cipher_extra_spec_t "):] + fname = re.match ("[a-zA-Z0-9_]*", fname).group () + chmsg = "(%s): Removed." % fname + if nch: + chlognew = "%s\n %s" % (chlognew, chmsg) + else: + chlognew = "%s %s" % (chlognew, chmsg) + nch = True + continue + m = re.match ("md_extra_spec_t", line) + if isc and not m is None: + skip2 = True + fname = line[len ("md_extra_spec_t "):] + fname = re.match ("[a-zA-Z0-9_]*", fname).group () + chmsg = "(%s): Removed." % fname + if nch: + chlognew = "%s\n %s" % (chlognew, chmsg) + else: + chlognew = "%s %s" % (chlognew, chmsg) + nch = True + continue fw.write (line) if len (ciphernames) > 0 or len (mdnames) > 0: modname = cipher_file [0:len(cipher_file) - 2] @@ -120,20 +193,27 @@ for cipher_file in cipher_files: outfile = os.path.join (cipher_dir_out, "types.h") fw=open (outfile, "w") fw.write ("#include \n") -fw.write ("#include \n") +fw.write ("#include \n") chlog = "%s * types.h: New file.\n" % chlog fw.close () +outfile = os.path.join (cipher_dir_out, "memory.h") +fw=open (outfile, "w") +fw.write ("#include \n") +chlog = "%s * memory.h: New file.\n" % chlog +fw.close () + + outfile = os.path.join (cipher_dir_out, "cipher.h") fw=open (outfile, "w") fw.write ("#include \n") -fw.write ("#include \n") +fw.write ("#include \n") chlog = "%s * cipher.h: Likewise.\n" % chlog fw.close () outfile = os.path.join (cipher_dir_out, "g10lib.h") fw=open (outfile, "w") -fw.write ("#include \n") +fw.write ("#include \n") chlog = "%s * g10lib.h: Likewise.\n" % chlog fw.close () diff --git a/include/grub/gcry_wrap.h b/include/grub/cipher_wrap.h similarity index 92% rename from include/grub/gcry_wrap.h rename to include/grub/cipher_wrap.h index 37a1ee4d7..9e6242b7f 100644 --- a/include/grub/gcry_wrap.h +++ b/include/grub/cipher_wrap.h @@ -68,4 +68,17 @@ grub_assert_real (const char *file, int line, int cond) grub_fatal ("Assertion failed at %s:%d\n", file, line); } +/* Selftests are in separate modules. */ +static inline char * +selftest (void) +{ + return NULL; +} + +static inline int +fips_mode (void) +{ + return 0; +} + #endif diff --git a/include/grub/crypto.h b/include/grub/crypto.h index bd236116d..17f14de86 100644 --- a/include/grub/crypto.h +++ b/include/grub/crypto.h @@ -64,6 +64,7 @@ typedef enum GPG_ERR_WRONG_PUBKEY_ALGO, } gcry_err_code_t; #define gpg_err_code_t gcry_err_code_t +#define gpg_error_t gcry_err_code_t enum gcry_cipher_modes {