Module Name:    src
Committed By:   jhigh
Date:           Sat Apr 18 19:27:49 UTC 2020

Modified Files:
        src/crypto/external/bsd/netpgp/dist: configure.ac
        src/crypto/external/bsd/netpgp/dist/src/lib: config.h.in misc.c
            symmetric.c

Log Message:
added blowfish symmetric cipher per RFC4880 9.2


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/crypto/external/bsd/netpgp/dist/configure.ac
cvs rdiff -u -r1.17 -r1.18 \
    src/crypto/external/bsd/netpgp/dist/src/lib/config.h.in
cvs rdiff -u -r1.42 -r1.43 src/crypto/external/bsd/netpgp/dist/src/lib/misc.c
cvs rdiff -u -r1.18 -r1.19 \
    src/crypto/external/bsd/netpgp/dist/src/lib/symmetric.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/crypto/external/bsd/netpgp/dist/configure.ac
diff -u src/crypto/external/bsd/netpgp/dist/configure.ac:1.42 src/crypto/external/bsd/netpgp/dist/configure.ac:1.43
--- src/crypto/external/bsd/netpgp/dist/configure.ac:1.42	Sun Mar  9 00:33:50 2014
+++ src/crypto/external/bsd/netpgp/dist/configure.ac	Sat Apr 18 19:27:49 2020
@@ -1,10 +1,10 @@
-# $NetBSD: configure.ac,v 1.42 2014/03/09 00:33:50 agc Exp $
+# $NetBSD: configure.ac,v 1.43 2020/04/18 19:27:49 jhigh Exp $
 #
 # Process this file with autoconf to produce a configure script.
 
 AC_INIT([netpgp],[20140220],[Alistair Crooks <a...@netbsd.org> c0596823])
 AC_PREREQ(2.69)
-AC_REVISION([$Revision: 1.42 $])
+AC_REVISION([$Revision: 1.43 $])
 
 AS_SHELL_SANITIZE
 
@@ -60,7 +60,7 @@ AC_CHECK_HEADERS([dmalloc.h direct.h err
 AC_CHECK_HEADERS([openssl/aes.h openssl/bn.h openssl/camellia.h openssl/cast.h \
 		  openssl/des.h openssl/dsa.h openssl/err.h openssl/idea.h \
 		  openssl/md5.h openssl/rand.h openssl/rsa.h openssl/sha.h \
-		  openssl/err.h openssl/sha.h])
+		  openssl/err.h openssl/sha.h openssl/blowfish.h])
 AC_CHECK_HEADERS([sys/cdefs.h sys/file.h sys/mman.h sys/param.h \
                   sys/resource.h sys/uio.h])
 

Index: src/crypto/external/bsd/netpgp/dist/src/lib/config.h.in
diff -u src/crypto/external/bsd/netpgp/dist/src/lib/config.h.in:1.17 src/crypto/external/bsd/netpgp/dist/src/lib/config.h.in:1.18
--- src/crypto/external/bsd/netpgp/dist/src/lib/config.h.in:1.17	Mon Feb 17 06:38:07 2014
+++ src/crypto/external/bsd/netpgp/dist/src/lib/config.h.in	Sat Apr 18 19:27:48 2020
@@ -39,6 +39,9 @@
 /* Define to 1 if you have the <openssl/aes.h> header file. */
 #undef HAVE_OPENSSL_AES_H
 
+/* Define to 1 if you have the <openssl/blowfish.h> header file. */
+#undef HAVE_OPENSSL_BLOWFISH_H
+
 /* Define to 1 if you have the <openssl/bn.h> header file. */
 #undef HAVE_OPENSSL_BN_H
 
@@ -120,8 +123,7 @@
 /* Define to 1 if you have the <zlib.h> header file. */
 #undef HAVE_ZLIB_H
 
-/* Define to the sub-directory in which libtool stores uninstalled libraries.
-   */
+/* Define to the sub-directory where libtool stores uninstalled libraries. */
 #undef LT_OBJDIR
 
 /* Name of package */

Index: src/crypto/external/bsd/netpgp/dist/src/lib/misc.c
diff -u src/crypto/external/bsd/netpgp/dist/src/lib/misc.c:1.42 src/crypto/external/bsd/netpgp/dist/src/lib/misc.c:1.43
--- src/crypto/external/bsd/netpgp/dist/src/lib/misc.c:1.42	Tue Nov 13 14:52:30 2018
+++ src/crypto/external/bsd/netpgp/dist/src/lib/misc.c	Sat Apr 18 19:27:48 2020
@@ -57,7 +57,7 @@
 
 #if defined(__NetBSD__)
 __COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
-__RCSID("$NetBSD: misc.c,v 1.42 2018/11/13 14:52:30 mlelstv Exp $");
+__RCSID("$NetBSD: misc.c,v 1.43 2020/04/18 19:27:48 jhigh Exp $");
 #endif
 
 #include <sys/types.h>
@@ -816,6 +816,7 @@ static str2cipher_t	str2cipher[] = {
 	{	"idea",			PGP_SA_IDEA		},
 	{	"aes128",		PGP_SA_AES_128		},
 	{	"aes256",		PGP_SA_AES_256		},
+	{	"blowfish",		PGP_SA_BLOWFISH		},
 	{	"camellia128",		PGP_SA_CAMELLIA_128	},
 	{	"camellia256",		PGP_SA_CAMELLIA_256	},
 	{	"tripledes",		PGP_SA_TRIPLEDES	},

Index: src/crypto/external/bsd/netpgp/dist/src/lib/symmetric.c
diff -u src/crypto/external/bsd/netpgp/dist/src/lib/symmetric.c:1.18 src/crypto/external/bsd/netpgp/dist/src/lib/symmetric.c:1.19
--- src/crypto/external/bsd/netpgp/dist/src/lib/symmetric.c:1.18	Sun Nov  7 08:39:59 2010
+++ src/crypto/external/bsd/netpgp/dist/src/lib/symmetric.c	Sat Apr 18 19:27:48 2020
@@ -54,7 +54,7 @@
 
 #if defined(__NetBSD__)
 __COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
-__RCSID("$NetBSD: symmetric.c,v 1.18 2010/11/07 08:39:59 agc Exp $");
+__RCSID("$NetBSD: symmetric.c,v 1.19 2020/04/18 19:27:48 jhigh Exp $");
 #endif
 
 #include "crypto.h"
@@ -82,6 +82,10 @@ __RCSID("$NetBSD: symmetric.c,v 1.18 201
 #include <openssl/camellia.h>
 #endif
 
+#ifdef HAVE_OPENSSL_BLOWFISH_H
+#include <openssl/blowfish.h>
+#endif
+
 #include "crypto.h"
 #include "netpgpdefs.h"
 
@@ -192,6 +196,81 @@ static pgp_crypt_t cast5 =
 	TRAILER
 };
 
+#ifdef HAVE_OPENSSL_BLOWFISH_H
+
+/* RFC 4880 9.2 Blowfish 128 */
+#define BLOWFISH_KEY_LENGTH	16
+
+static int
+blowfish_init(pgp_crypt_t *crypt)
+{
+        if (crypt->encrypt_key) {
+                free(crypt->encrypt_key);
+        }
+        if (crypt->keysize != BLOWFISH_KEY_LENGTH) {
+               (void) fprintf(stderr, "blowfish_init: keysize wrong\n");
+               return 0;
+        }
+        if ((crypt->encrypt_key = calloc(1, sizeof(BF_KEY))) == NULL) {
+                (void) fprintf(stderr, "blowfish_init: alloc failure\n");
+                return 0;
+        }
+        BF_set_key(crypt->encrypt_key, (int)crypt->keysize, crypt->key);
+        if ((crypt->decrypt_key = calloc(1, sizeof(BF_KEY))) == NULL) {
+                (void) fprintf(stderr, "blowfish_init: alloc failure\n");
+                return 0;
+        }
+        BF_set_key(crypt->decrypt_key, (int)crypt->keysize, crypt->key);
+        return 1;
+}
+
+static void
+blowfish_block_encrypt(pgp_crypt_t *crypt, void *out, const void *in)
+{
+        BF_ecb_encrypt(in, out, crypt->encrypt_key, BF_ENCRYPT);
+}
+
+static void
+blowfish_block_decrypt(pgp_crypt_t *crypt, void *out, const void *in)
+{
+        BF_ecb_encrypt(in, out, crypt->encrypt_key, BF_DECRYPT);
+}
+
+static void
+blowfish_cfb_encrypt(pgp_crypt_t *crypt, void *out, const void *in, size_t count)
+{
+        BF_cfb64_encrypt(in, out, (long)count,
+                         crypt->encrypt_key, crypt->iv, &crypt->num,
+                         BF_ENCRYPT);
+}
+
+static void
+blowfish_cfb_decrypt(pgp_crypt_t *crypt, void *out, const void *in, size_t count)
+{
+        BF_cfb64_encrypt(in, out, (long)count,
+                         crypt->encrypt_key, crypt->iv, &crypt->num,
+                         BF_DECRYPT);
+}
+
+static pgp_crypt_t blowfish =
+{
+        PGP_SA_BLOWFISH,
+        BF_BLOCK,
+        BLOWFISH_KEY_LENGTH,
+        std_set_iv,
+        std_set_key,
+        blowfish_init,
+        std_resync,
+        blowfish_block_encrypt,
+        blowfish_block_decrypt,
+        blowfish_cfb_encrypt,
+        blowfish_cfb_decrypt,
+        std_finish,
+        TRAILER
+};
+
+#endif /* HAVE_OPENSSL_BLOWFISH_H */
+
 #ifndef OPENSSL_NO_IDEA
 static int 
 idea_init(pgp_crypt_t *crypt)
@@ -633,6 +712,11 @@ get_proto(pgp_symm_alg_t alg)
 #endif
 	case PGP_SA_TRIPLEDES:
 		return &tripledes;
+#if defined HAVE_OPENSSL_BLOWFISH_H
+	case PGP_SA_BLOWFISH:
+		return &blowfish;
+#endif
+
 	default:
 		(void) fprintf(stderr, "Unknown algorithm: %d (%s)\n",
 			alg, pgp_show_symm_alg(alg));
@@ -756,6 +840,9 @@ pgp_is_sa_supported(pgp_symm_alg_t alg)
 	case PGP_SA_AES_128:
 	case PGP_SA_AES_256:
 	case PGP_SA_CAST5:
+#if defined(HAVE_OPENSSL_BLOWFISH_H)
+	case PGP_SA_BLOWFISH:
+#endif
 	case PGP_SA_TRIPLEDES:
 #if defined(HAVE_OPENSSL_CAMELLIA_H) && !defined(OPENSSL_NO_CAMELLIA)
 	case PGP_SA_CAMELLIA_128:

Reply via email to