From 019924627e8680f7d95d36d5e1d07b34d5d987e6 Mon Sep 17 00:00:00 2001 From: Zhi Guan Date: Sun, 26 Mar 2017 15:04:30 +0800 Subject: [PATCH] update serpent module --- Configure | 5 ++++- crypto/serpent/build.info | 2 ++ myserpent.c => crypto/serpent/serpent.c | 2 +- crypto/serpent/serpent.d.tmp | 2 ++ myserpent.h => include/openssl/serpent.h | 19 +++++++++++++++++++ test/build.info | 7 ++++++- test/recipes/05-test_serpenet.t | 12 ++++++++++++ test.c => test/serpenttest.c | 18 +++++++++++++++--- 8 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 crypto/serpent/build.info rename myserpent.c => crypto/serpent/serpent.c (99%) create mode 100644 crypto/serpent/serpent.d.tmp rename myserpent.h => include/openssl/serpent.h (67%) create mode 100644 test/recipes/05-test_serpenet.t rename test.c => test/serpenttest.c (97%) diff --git a/Configure b/Configure index 3e96ea4f..63c6049a 100755 --- a/Configure +++ b/Configure @@ -312,7 +312,8 @@ $config{sdirs} = [ "evp", "asn1", "pem", "x509", "x509v3", "conf", "txt_db", "pkcs7", "pkcs12", "comp", "ocsp", "ui", "cms", "ts", "srp", "cmac", "ct", "async", "kdf", "sm3", "sms4", "kdf2", "ecies", "ffx", "sm2", "paillier", "cpk", "otp", "gmapi", "ec2", - "bfibe", "bb1ibe", "sm9", "saf", "sdf", "skf", "sof", "zuc" + "bfibe", "bb1ibe", "sm9", "saf", "sdf", "skf", "sof", "zuc", + "serpent" ]; # Known TLS and DTLS protocols @@ -432,6 +433,7 @@ my @disablables = ( "pem", "pkcs7", "pkcs12", + "serpent", ); foreach my $proto ((@tls, @dtls)) { @@ -474,6 +476,7 @@ our %disabled = ( # "what" => "comment" "bb1ibe" => "default", "saf" => "default", "sof" => "default", + "serpent" => "default", ); # Note: => pair form used for aesthetics, not to truly make a hash table diff --git a/crypto/serpent/build.info b/crypto/serpent/build.info new file mode 100644 index 00000000..eee86dc9 --- /dev/null +++ b/crypto/serpent/build.info @@ -0,0 +1,2 @@ +LIBS=../../libcrypto +SOURCE[../../libcrypto]=serpent.c diff --git a/myserpent.c b/crypto/serpent/serpent.c similarity index 99% rename from myserpent.c rename to crypto/serpent/serpent.c index 82d9e4f0..f0f00026 100644 --- a/myserpent.c +++ b/crypto/serpent/serpent.c @@ -9,7 +9,7 @@ #include #include -#include "myserpent.h" +#include #define IN #define OUT diff --git a/crypto/serpent/serpent.d.tmp b/crypto/serpent/serpent.d.tmp new file mode 100644 index 00000000..b65b5bff --- /dev/null +++ b/crypto/serpent/serpent.d.tmp @@ -0,0 +1,2 @@ +crypto/serpent/serpent.o: crypto/serpent/serpent.c \ + include/openssl/serpent.h diff --git a/myserpent.h b/include/openssl/serpent.h similarity index 67% rename from myserpent.h rename to include/openssl/serpent.h index ba8726c5..e649904b 100644 --- a/myserpent.h +++ b/include/openssl/serpent.h @@ -17,3 +17,22 @@ extern char sb7(char sb7_in); #define rotr(x,n) (((x) >> ((int)(n))) | ((x) << (32 - (int)(n)))) #endif + +/* +The following should be implemented + +#define SERPENT_KEY_LENGTH ?? +#define SERPENT_BLOCK_SIZE ?? +#define SERPENT_IV_LENGTH (SERPENT_BLOCK_SIZE) +#define SERPENT_NUM_ROUNDS ?? + +typedef struct { + uint32_t rk[SMS4_NUM_ROUNDS]; +} serpent_key_t; + +void serpent_set_encrypt_key(serpent_key_t *key, const unsigned char *user_key); +void serpent_set_decrypt_key(serpent_key_t *key, const unsigned char *user_key); +void serpent_encrypt(const unsigned char *in, unsigned char *out, const serpent_key_t *key); +void serpent_decrypt(const unsigned char *in, unsigned char *out, const serpent_key_t *key); + +*/ diff --git a/test/build.info b/test/build.info index 602f95ef..066e2b70 100644 --- a/test/build.info +++ b/test/build.info @@ -20,7 +20,8 @@ IF[{- !$disabled{tests} -}] sm3test sms4test kdf2test eciestest ffxtest sm2test \ pailliertest cpktest otptest gmapitest ec2test \ bfibetest bb1ibetest sm9test \ - saftest sdftest skftest softest zuctest + saftest sdftest skftest softest zuctest \ + serpenttest SOURCE[aborttest]=aborttest.c INCLUDE[aborttest]=../include @@ -363,6 +364,10 @@ IF[{- !$disabled{tests} -}] INCLUDE[zuctest]=../include DEPEND[zuctest]=../libcrypto + SOURCE[serpenttest]=serpenttest.c + INCLUDE[serpenttest]=../include + DEPEND[serpenttest]=../libcrypto + IF[{- !$disabled{shared} -}] PROGRAMS_NO_INST=shlibloadtest SOURCE[shlibloadtest]=shlibloadtest.c diff --git a/test/recipes/05-test_serpenet.t b/test/recipes/05-test_serpenet.t new file mode 100644 index 00000000..c1e46457 --- /dev/null +++ b/test/recipes/05-test_serpenet.t @@ -0,0 +1,12 @@ +#! /usr/bin/env perl +# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved. +# +# Licensed under the OpenSSL license (the "License"). You may not use +# this file except in compliance with the License. You can obtain a copy +# in the file LICENSE in the source distribution or at +# https://www.openssl.org/source/license.html + + +use OpenSSL::Test::Simple; + +simple_test("test_serpent", "serpenttest", "serpent"); diff --git a/test.c b/test/serpenttest.c similarity index 97% rename from test.c rename to test/serpenttest.c index 30b10b56..c4708b33 100644 --- a/test.c +++ b/test/serpenttest.c @@ -1,6 +1,18 @@ -#include -#include "myserpent.h" +#include +#include +#include +#include "../e_os.h" + +#ifdef OPENSSL_NO_SERPENT +int main(int argc, char **argv) +{ + printf("No Serpent support\n"); + return 0; +} +#else + +#include int main(int argc, char* argv[]){ @@ -267,4 +279,4 @@ int main(int argc, char* argv[]){ fclose(fp); return 0; } - +#endif