Skip to content

Commit

Permalink
use musl's blowfish for passwd encryption
Browse files Browse the repository at this point in the history
  • Loading branch information
rofl0r committed Aug 27, 2012
1 parent d5c46f8 commit da9aec5
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
61 changes: 61 additions & 0 deletions KEEP/busybox-blowfish.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
From 2227a5969bbf83d05cc6b738670e38d0b56cd437 Mon Sep 17 00:00:00 2001
From: rofl0r <retnyg@gmx.net>
Date: Mon, 27 Aug 2012 21:34:55 +0200
Subject: [PATCH] add blowfish support to bb

---
libbb/pw_encrypt.c | 23 ++++++++++++++++++++---
1 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/libbb/pw_encrypt.c b/libbb/pw_encrypt.c
index 39ffa08..d2fb2b9 100644
--- a/libbb/pw_encrypt.c
+++ b/libbb/pw_encrypt.c
@@ -53,9 +53,20 @@ char* FAST_FUNC crypt_make_pw_salt(char salt[MAX_PW_SALT_LEN], const char *algo)
int len = 2/2;
char *salt_ptr = salt;
if (algo[0] != 'd') { /* not des */
- len = 8/2; /* so far assuming md5 */
*salt_ptr++ = '$';
- *salt_ptr++ = '1';
+ if(algo[0] == 'b') {
+ // blowfish
+ *salt_ptr++ = '2';
+ *salt_ptr++ = 'a';
+ *salt_ptr++ = '$';
+ // 8 rounds
+ *salt_ptr++ = '0';
+ *salt_ptr++ = '8';
+ len = 22/2;
+ } else {
+ *salt_ptr++ = '1';
+ if (algo[0] == 'm') len = 8/2; /* so far assuming md5 */
+ }
*salt_ptr++ = '$';
#if !ENABLE_USE_BB_CRYPT || ENABLE_USE_BB_CRYPT_SHA
if (algo[0] == 's') { /* sha */
@@ -95,6 +106,11 @@ to64(char *s, unsigned v, int n)
/* Other advanced crypt ids (TODO?): */
/* $2$ or $2a$: Blowfish */

+static char *bf_crypt(const char *key, const char *salt) {
+ // use musl-builtin crypt
+ return crypt(key, salt);
+}
+
static struct const_des_ctx *des_cctx;
static struct des_ctx *des_ctx;

@@ -109,7 +125,8 @@ static char *my_crypt(const char *key, const char *salt)
if (salt[1] == '5' || salt[1] == '6')
return sha_crypt((char*)key, (char*)salt);
#endif
- }
+ } else if (salt[0] == '$' && salt[1] == '2' && salt[2] == 'a' && salt[3] == '$')
+ return bf_crypt(key, salt);

if (!des_cctx)
des_cctx = const_des_init();
--
1.7.3.4

2 changes: 1 addition & 1 deletion KEEP/busybox.stage1.config
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ CONFIG_PASSWD=y
CONFIG_FEATURE_PASSWD_WEAK_CHECK=y
CONFIG_CRYPTPW=y
CONFIG_CHPASSWD=y
CONFIG_FEATURE_DEFAULT_PASSWD_ALGO="sha512"
CONFIG_FEATURE_DEFAULT_PASSWD_ALGO="bf"
CONFIG_SU=y
CONFIG_FEATURE_SU_SYSLOG=y
# CONFIG_FEATURE_SU_CHECKS_SHELLS is not set
Expand Down
1 change: 1 addition & 0 deletions pkg/busybox
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ http://www.busybox.net/downloads/busybox-1.20.2.tar.bz2

cp "$K/busybox.stage1.config" .config
patch -p1 < "$K/busybox.patch" || exit 1
patch -p1 < "$K/busybox-blowfish.patch" || exit 1

#__inline seems to get activated when -std=gnu99 is used, causing havoc
sed -i 's,__inline,,' ./scripts/kconfig/zconf.hash.c_shipped
Expand Down

0 comments on commit da9aec5

Please sign in to comment.