Blame SOURCES/0500-CHAP-SHA-1-SHA-256-SHA3-256-via-OpenSSL-s-libcrypto.patch

6b208b
From 579f12dfa2dab3e2b7a3c02ee32ac624de644f58 Mon Sep 17 00:00:00 2001
6b208b
From: Chris Leech <cleech@redhat.com>
6b208b
Date: Thu, 13 Jun 2019 16:07:07 -0700
6b208b
Subject: [PATCH] CHAP SHA-1, SHA-256, SHA3-256 via OpenSSL's libcrypto
6b208b
6b208b
Extended CHAP authentication modes using newer hash digest functions
6b208b
than MD5.  SHA-256 and SHA3-256 should be usable in FIPS-140
6b208b
environments for some time.
6b208b
6b208b
These CHAP algorithms have been registered with IANA for this purpose.
6b208b
https://www.iana.org/assignments/ppp-numbers/ppp-numbers.xhtml#ppp-numbers-9
6b208b
6b208b
Makes OpenSSL libcrypto use a requirement, replacing the in tree MD5
6b208b
implementation as well (and removing the unused SHA1 code).
6b208b
6b208b
Signed-off-by: Chris Leech <cleech@redhat.com>
6b208b
(cherry picked from commit 48a4e5b475836bcb952fb53a8bde45bdf68fe38f)
6b208b
---
6b208b
 usr/Makefile |   6 +-
6b208b
 usr/auth.c   | 157 ++++++++++++++++++++++++----------
6b208b
 usr/auth.h   |  11 ++-
6b208b
 usr/md5.c    | 236 ---------------------------------------------------
6b208b
 usr/md5.h    |  60 -------------
6b208b
 usr/sha1.c   | 167 ------------------------------------
6b208b
 usr/sha1.h   |  27 ------
6b208b
 7 files changed, 126 insertions(+), 538 deletions(-)
6b208b
 delete mode 100644 usr/md5.c
6b208b
 delete mode 100644 usr/md5.h
6b208b
 delete mode 100644 usr/sha1.c
6b208b
 delete mode 100644 usr/sha1.h
6b208b
6b208b
diff --git a/usr/Makefile b/usr/Makefile
6b208b
index 742a0fb..db40c3a 100644
6b208b
--- a/usr/Makefile
6b208b
+++ b/usr/Makefile
6b208b
@@ -45,8 +45,8 @@ PROGRAMS = iscsid iscsiadm iscsistart
6b208b
 # libc compat files
6b208b
 SYSDEPS_SRCS = $(sort $(wildcard ../utils/sysdeps/*.o))
6b208b
 # sources shared between iscsid, iscsiadm and iscsistart
6b208b
-ISCSI_LIB_SRCS = iscsi_util.o io.o auth.o iscsi_timer.o login.o log.o md5.o \
6b208b
-	sha1.o iface.o idbm.o sysfs.o host.o session_info.o iscsi_sysfs.o \
6b208b
+ISCSI_LIB_SRCS = iscsi_util.o io.o auth.o iscsi_timer.o login.o log.o \
6b208b
+	iface.o idbm.o sysfs.o host.o session_info.o iscsi_sysfs.o \
6b208b
 	iscsi_net_util.o iscsid_req.o transport.o iser.o cxgbi.o be2iscsi.o \
6b208b
 	initiator_common.o iscsi_err.o flashnode.o uip_mgmt_ipc.o \
6b208b
 	$(IPC_OBJ)  $(SYSDEPS_SRCS)
6b208b
@@ -70,7 +70,7 @@ iscsiadm: $(ISCSI_LIB_SRCS) $(DISCOVERY_SRCS) iscsiadm.o session_mgmt.o mntcheck
6b208b
 
6b208b
 iscsistart: $(ISCSI_LIB_SRCS) $(INITIATOR_SRCS) $(FW_BOOT_SRCS) \
6b208b
 		iscsistart.o statics.o
6b208b
-	$(CC) $(CFLAGS) $^ -o $@ -lrt $(LDFLAGS)
6b208b
+	$(CC) $(CFLAGS) $^ -o $@ -lcrypto -lrt $(LDFLAGS)
6b208b
 clean:
6b208b
 	rm -f *.o $(PROGRAMS) .depend $(LIBSYS)
6b208b
 
6b208b
diff --git a/usr/auth.c b/usr/auth.c
6b208b
index e44a279..afb4ea3 100644
6b208b
--- a/usr/auth.c
6b208b
+++ b/usr/auth.c
6b208b
@@ -34,7 +34,6 @@
6b208b
 #include "sysdeps.h"
6b208b
 #include "auth.h"
6b208b
 #include "initiator.h"
6b208b
-#include "md5.h"
6b208b
 #include "log.h"
6b208b
 
6b208b
 static const char acl_hexstring[] = "0123456789abcdefABCDEF";
6b208b
@@ -43,9 +42,11 @@ static const char acl_base64_string[] =
6b208b
 static const char acl_authmethod_set_chap_alg_list[] = "CHAP";
6b208b
 static const char acl_reject_option_name[] = "Reject";
6b208b
 
6b208b
-void auth_md5_init(struct MD5Context *);
6b208b
-void auth_md5_update(struct MD5Context *, unsigned char *, unsigned int);
6b208b
-void auth_md5_final(unsigned char *, struct MD5Context *);
6b208b
+#include <openssl/evp.h>
6b208b
+static int auth_hash_init(EVP_MD_CTX **context, int chap_alg);
6b208b
+static void auth_hash_update(EVP_MD_CTX *context, unsigned char *md, unsigned int);
6b208b
+static unsigned int auth_hash_final(unsigned char *, EVP_MD_CTX *context);
6b208b
+
6b208b
 void get_random_bytes(unsigned char *data, unsigned int length);
6b208b
 size_t strlcpy(char *, const char *, size_t);
6b208b
 size_t strlcat(char *, const char *, size_t);
6b208b
@@ -57,18 +58,19 @@ acl_chap_compute_rsp(struct iscsi_acl *client, int rmt_auth, unsigned int id,
6b208b
 		     unsigned char *response_data)
6b208b
 {
6b208b
 	unsigned char id_data[1];
6b208b
-	struct MD5Context context;
6b208b
+	EVP_MD_CTX *context = NULL;
6b208b
 	unsigned char out_data[AUTH_STR_MAX_LEN];
6b208b
 	unsigned int out_length = AUTH_STR_MAX_LEN;
6b208b
 
6b208b
 	if (!client->passwd_present)
6b208b
 		return AUTH_DBG_STATUS_LOCAL_PASSWD_NOT_SET;
6b208b
 
6b208b
-	auth_md5_init(&context);
6b208b
+	if (auth_hash_init(&context, client->negotiated_chap_alg) != 0)
6b208b
+		return AUTH_DBG_STATUS_AUTH_FAIL;
6b208b
 
6b208b
 	/* id byte */
6b208b
 	id_data[0] = id;
6b208b
-	auth_md5_update(&context, id_data, 1);
6b208b
+	auth_hash_update(context, id_data, 1);
6b208b
 
6b208b
 	/* decrypt password */
6b208b
 	if (acl_data(out_data, &out_length, client->passwd_data,
6b208b
@@ -79,15 +81,15 @@ acl_chap_compute_rsp(struct iscsi_acl *client, int rmt_auth, unsigned int id,
6b208b
 		return AUTH_DBG_STATUS_PASSWD_TOO_SHORT_WITH_NO_IPSEC;
6b208b
 
6b208b
 	/* shared secret */
6b208b
-	auth_md5_update(&context, out_data, out_length);
6b208b
+	auth_hash_update(context, out_data, out_length);
6b208b
 
6b208b
 	/* clear decrypted password */
6b208b
 	memset(out_data, 0, AUTH_STR_MAX_LEN);
6b208b
 
6b208b
 	/* challenge value */
6b208b
-	auth_md5_update(&context, challenge_data, challenge_length);
6b208b
+	auth_hash_update(context, challenge_data, challenge_length);
6b208b
 
6b208b
-	auth_md5_final(response_data, &context);
6b208b
+	auth_hash_final(response_data, context);
6b208b
 
6b208b
 	return AUTH_DBG_STATUS_NOT_SET;	/* no error */
6b208b
 }
6b208b
@@ -103,8 +105,8 @@ acl_chap_auth_request(struct iscsi_acl *client, char *username, unsigned int id,
6b208b
 		      unsigned int rsp_length)
6b208b
 {
6b208b
 	iscsi_session_t *session = client->session_handle;
6b208b
-	struct MD5Context context;
6b208b
-	unsigned char verify_data[16];
6b208b
+	EVP_MD_CTX *context = NULL;
6b208b
+	unsigned char verify_data[client->chap_challenge_len];
6b208b
 
6b208b
 	/* the expected credentials are in the session */
6b208b
 	if (session->username_in == NULL) {
6b208b
@@ -137,21 +139,22 @@ acl_chap_auth_request(struct iscsi_acl *client, char *username, unsigned int id,
6b208b
 		return AUTH_STATUS_FAIL;
6b208b
 	}
6b208b
 
6b208b
-	auth_md5_init(&context);
6b208b
+	if (auth_hash_init(&context, client->negotiated_chap_alg) != 0)
6b208b
+		return AUTH_STATUS_FAIL;
6b208b
 
6b208b
 	/* id byte */
6b208b
 	verify_data[0] = id;
6b208b
-	auth_md5_update(&context, verify_data, 1);
6b208b
+	auth_hash_update(context, verify_data, 1);
6b208b
 
6b208b
 	/* shared secret */
6b208b
-	auth_md5_update(&context, (unsigned char *)session->password_in,
6b208b
+	auth_hash_update(context, (unsigned char *)session->password_in,
6b208b
 			session->password_in_length);
6b208b
 
6b208b
 	/* challenge value */
6b208b
-	auth_md5_update(&context, (unsigned char *)challenge_data,
6b208b
+	auth_hash_update(context, (unsigned char *)challenge_data,
6b208b
 			challenge_length);
6b208b
 
6b208b
-	auth_md5_final(verify_data, &context);
6b208b
+	auth_hash_final(verify_data, context);
6b208b
 
6b208b
 	if (memcmp(response_data, verify_data, sizeof(verify_data)) == 0) {
6b208b
 		log_debug(1, "initiator authenticated target %s",
6b208b
@@ -164,23 +167,54 @@ acl_chap_auth_request(struct iscsi_acl *client, char *username, unsigned int id,
6b208b
 	return AUTH_STATUS_FAIL;
6b208b
 }
6b208b
 
6b208b
-void
6b208b
-auth_md5_init(struct MD5Context *context)
6b208b
-{
6b208b
-	MD5Init(context);
6b208b
+static int auth_hash_init(EVP_MD_CTX **context, int chap_alg) {
6b208b
+	const EVP_MD *digest = NULL;
6b208b
+	*context = EVP_MD_CTX_new();
6b208b
+	int rc;
6b208b
+
6b208b
+	switch (chap_alg) {
6b208b
+	case AUTH_CHAP_ALG_MD5:
6b208b
+		digest = EVP_md5();
6b208b
+		break;
6b208b
+	case AUTH_CHAP_ALG_SHA1:
6b208b
+		digest = EVP_sha1();
6b208b
+		break;
6b208b
+	case AUTH_CHAP_ALG_SHA256:
6b208b
+		digest = EVP_sha256();
6b208b
+		break;
6b208b
+	case AUTH_CHAP_ALG_SHA3_256:
6b208b
+		digest = EVP_sha3_256();
6b208b
+		break;
6b208b
+	}
6b208b
+
6b208b
+	if (*context == NULL)
6b208b
+		goto fail_context;
6b208b
+	if (digest == NULL)
6b208b
+		goto fail_digest;
6b208b
+	rc = EVP_DigestInit_ex(*context, digest, NULL);
6b208b
+	if (!rc)
6b208b
+		goto fail_init;
6b208b
+
6b208b
+	return 0;
6b208b
+
6b208b
+fail_init:
6b208b
+fail_digest:
6b208b
+	EVP_MD_CTX_free(*context);
6b208b
+	*context = NULL;
6b208b
+fail_context:
6b208b
+	return -1;
6b208b
 }
6b208b
 
6b208b
-void
6b208b
-auth_md5_update(struct MD5Context *context, unsigned char *data,
6b208b
-		unsigned int length)
6b208b
-{
6b208b
-	MD5Update(context, data, length);
6b208b
+static void auth_hash_update(EVP_MD_CTX *context, unsigned char *data, unsigned int length) {
6b208b
+	EVP_DigestUpdate(context, data, length);
6b208b
 }
6b208b
 
6b208b
-void
6b208b
-auth_md5_final(unsigned char *hash, struct MD5Context *context)
6b208b
-{
6b208b
-	MD5Final(hash, context);
6b208b
+static unsigned int auth_hash_final(unsigned char *hash, EVP_MD_CTX *context) {
6b208b
+	unsigned int md_len;
6b208b
+	EVP_DigestFinal_ex(context, hash, &md_len);
6b208b
+	EVP_MD_CTX_free(context);
6b208b
+	context = NULL;
6b208b
+	return md_len;
6b208b
 }
6b208b
 
6b208b
 void
6b208b
@@ -301,6 +335,9 @@ static int
6b208b
 acl_chk_chap_alg_optn(int chap_algorithm)
6b208b
 {
6b208b
 	if (chap_algorithm == AUTH_OPTION_NONE ||
6b208b
+	    chap_algorithm == AUTH_CHAP_ALG_SHA3_256 ||
6b208b
+	    chap_algorithm == AUTH_CHAP_ALG_SHA256 ||
6b208b
+	    chap_algorithm == AUTH_CHAP_ALG_SHA1 ||
6b208b
 	    chap_algorithm == AUTH_CHAP_ALG_MD5)
6b208b
 		return 0;
6b208b
 
6b208b
@@ -701,6 +738,20 @@ acl_chk_chap_alg_key(struct iscsi_acl *client)
6b208b
 			if (number == (unsigned long)client->chap_alg_list[i])
6b208b
 			{
6b208b
 				client->negotiated_chap_alg = number;
6b208b
+				switch (number) {
6b208b
+				case AUTH_CHAP_ALG_MD5:
6b208b
+					client->chap_challenge_len = AUTH_CHAP_MD5_RSP_LEN;
6b208b
+					break;
6b208b
+				case AUTH_CHAP_ALG_SHA1:
6b208b
+					client->chap_challenge_len = AUTH_CHAP_SHA1_RSP_LEN;
6b208b
+					break;
6b208b
+				case AUTH_CHAP_ALG_SHA256:
6b208b
+					client->chap_challenge_len = AUTH_CHAP_SHA256_RSP_LEN;
6b208b
+					break;
6b208b
+				case AUTH_CHAP_ALG_SHA3_256:
6b208b
+					client->chap_challenge_len = AUTH_CHAP_SHA3_256_RSP_LEN;
6b208b
+					break;
6b208b
+				}
6b208b
 				return;
6b208b
 			}
6b208b
 	}
6b208b
@@ -816,7 +867,7 @@ static void
6b208b
 acl_local_auth(struct iscsi_acl *client)
6b208b
 {
6b208b
 	unsigned int chap_identifier;
6b208b
-	unsigned char response_data[AUTH_CHAP_RSP_LEN];
6b208b
+	unsigned char response_data[AUTH_CHAP_RSP_MAX];
6b208b
 	unsigned long number;
6b208b
 	int status;
6b208b
 	enum auth_dbg_status dbg_status;
6b208b
@@ -848,7 +899,10 @@ acl_local_auth(struct iscsi_acl *client)
6b208b
 			client->local_state = AUTH_LOCAL_STATE_ERROR;
6b208b
 			client->dbg_status = AUTH_DBG_STATUS_CHAP_ALG_REJECT;
6b208b
 			break;
6b208b
-		} else if (client->negotiated_chap_alg != AUTH_CHAP_ALG_MD5) {
6b208b
+		} else if ((client->negotiated_chap_alg != AUTH_CHAP_ALG_SHA3_256) &&
6b208b
+			   (client->negotiated_chap_alg != AUTH_CHAP_ALG_SHA256) &&
6b208b
+			   (client->negotiated_chap_alg != AUTH_CHAP_ALG_SHA1) &&
6b208b
+			   (client->negotiated_chap_alg != AUTH_CHAP_ALG_MD5)) {
6b208b
 			client->local_state = AUTH_LOCAL_STATE_ERROR;
6b208b
 			client->dbg_status = AUTH_DBG_STATUS_CHAP_ALG_BAD;
6b208b
 			break;
6b208b
@@ -923,8 +977,8 @@ acl_local_auth(struct iscsi_acl *client)
6b208b
 			break;
6b208b
 		}
6b208b
 
6b208b
-		acl_data_to_text(response_data,
6b208b
-				 AUTH_CHAP_RSP_LEN, client->scratch_key_value,
6b208b
+		acl_data_to_text(response_data, client->chap_challenge_len,
6b208b
+				 client->scratch_key_value,
6b208b
 				 AUTH_STR_MAX_LEN);
6b208b
 		acl_set_key_value(&client->send_key_block,
6b208b
 				  AUTH_KEY_TYPE_CHAP_RSP,
6b208b
@@ -949,7 +1003,7 @@ acl_rmt_auth(struct iscsi_acl *client)
6b208b
 	unsigned char id_data[1];
6b208b
 	unsigned char response_data[AUTH_STR_MAX_LEN];
6b208b
 	unsigned int rsp_len = AUTH_STR_MAX_LEN;
6b208b
-	unsigned char my_rsp_data[AUTH_CHAP_RSP_LEN];
6b208b
+	unsigned char my_rsp_data[AUTH_CHAP_RSP_MAX];
6b208b
 	int status;
6b208b
 	enum auth_dbg_status dbg_status;
6b208b
 	const char *chap_rsp_key_val;
6b208b
@@ -1012,7 +1066,7 @@ acl_rmt_auth(struct iscsi_acl *client)
6b208b
 			break;
6b208b
 		}
6b208b
 
6b208b
-		if (rsp_len == AUTH_CHAP_RSP_LEN) {
6b208b
+		if (rsp_len == client->chap_challenge_len) {
6b208b
 			dbg_status = acl_chap_compute_rsp(client, 1,
6b208b
 							  client->send_chap_identifier,
6b208b
 							  client->send_chap_challenge.large_binary,
6b208b
@@ -1021,7 +1075,7 @@ acl_rmt_auth(struct iscsi_acl *client)
6b208b
 
6b208b
 			if (dbg_status == AUTH_DBG_STATUS_NOT_SET &&
6b208b
 			    memcmp(my_rsp_data, response_data,
6b208b
-				   AUTH_CHAP_RSP_LEN) == 0) {
6b208b
+				   client->chap_challenge_len) == 0) {
6b208b
 				client->rmt_state = AUTH_RMT_STATE_ERROR;
6b208b
 				client->dbg_status = AUTH_DBG_STATUS_PASSWD_IDENTICAL;
6b208b
 				break;
6b208b
@@ -1764,6 +1818,26 @@ acl_set_chap_alg_list(struct iscsi_acl *client, unsigned int option_count,
6b208b
 				   acl_chk_chap_alg_list);
6b208b
 }
6b208b
 
6b208b
+int
6b208b
+acl_init_chap_digests(int *value_list) {
6b208b
+	EVP_MD_CTX *context = EVP_MD_CTX_new();
6b208b
+	int i = 0;
6b208b
+
6b208b
+	if (EVP_DigestInit_ex(context, EVP_sha3_256(), NULL)) {
6b208b
+		value_list[i++] = AUTH_CHAP_ALG_SHA3_256;
6b208b
+	}
6b208b
+	if (EVP_DigestInit_ex(context, EVP_sha256(), NULL)) {
6b208b
+		value_list[i++] = AUTH_CHAP_ALG_SHA256;
6b208b
+	}
6b208b
+	if (EVP_DigestInit_ex(context, EVP_sha1(), NULL)) {
6b208b
+		value_list[i++] = AUTH_CHAP_ALG_SHA1;
6b208b
+	}
6b208b
+	if (EVP_DigestInit_ex(context, EVP_md5(), NULL)) {
6b208b
+		value_list[i++] = AUTH_CHAP_ALG_MD5;
6b208b
+	}
6b208b
+	return i;
6b208b
+}
6b208b
+
6b208b
 int
6b208b
 acl_init(int node_type, int buf_desc_count, struct auth_buffer_desc *buff_desc)
6b208b
 {
6b208b
@@ -1772,7 +1846,7 @@ acl_init(int node_type, int buf_desc_count, struct auth_buffer_desc *buff_desc)
6b208b
 	struct auth_str_block *send_str_blk;
6b208b
 	struct auth_large_binary *recv_chap_challenge;
6b208b
 	struct auth_large_binary *send_chap_challenge;
6b208b
-	int value_list[2];
6b208b
+	int value_list[3];
6b208b
 
6b208b
 	if (buf_desc_count != 5 || !buff_desc)
6b208b
 		return AUTH_STATUS_ERROR;
6b208b
@@ -1825,7 +1899,6 @@ acl_init(int node_type, int buf_desc_count, struct auth_buffer_desc *buff_desc)
6b208b
 	client->node_type = (enum auth_node_type) node_type;
6b208b
 	client->auth_rmt = 1;
6b208b
 	client->passwd_present = 0;
6b208b
-	client->chap_challenge_len = AUTH_CHAP_RSP_LEN;
6b208b
 	client->ip_sec = 0;
6b208b
 
6b208b
 	client->phase = AUTH_PHASE_CONFIGURE;
6b208b
@@ -1851,10 +1924,8 @@ acl_init(int node_type, int buf_desc_count, struct auth_buffer_desc *buff_desc)
6b208b
 		return AUTH_STATUS_ERROR;
6b208b
 	}
6b208b
 
6b208b
-	value_list[0] = AUTH_CHAP_ALG_MD5;
6b208b
-
6b208b
-	if (acl_set_chap_alg_list(client, 1, value_list) !=
6b208b
-	    AUTH_STATUS_NO_ERROR) {
6b208b
+	if (acl_set_chap_alg_list(client, acl_init_chap_digests(value_list),
6b208b
+					value_list) != AUTH_STATUS_NO_ERROR) {
6b208b
 		client->phase = AUTH_PHASE_ERROR;
6b208b
 		return AUTH_STATUS_ERROR;
6b208b
 	}
6b208b
diff --git a/usr/auth.h b/usr/auth.h
6b208b
index 2cc3489..f6dbbe4 100644
6b208b
--- a/usr/auth.h
6b208b
+++ b/usr/auth.h
6b208b
@@ -29,7 +29,11 @@ enum {
6b208b
 	AUTH_LARGE_BINARY_MAX_LEN = 1024,
6b208b
 	AUTH_RECV_END_MAX_COUNT = 10,
6b208b
 	ACL_SIGNATURE = 0x5984B2E3,
6b208b
-	AUTH_CHAP_RSP_LEN = 16,
6b208b
+	AUTH_CHAP_MD5_RSP_LEN = 16,
6b208b
+	AUTH_CHAP_SHA1_RSP_LEN = 20,
6b208b
+	AUTH_CHAP_SHA256_RSP_LEN = 32,
6b208b
+	AUTH_CHAP_SHA3_256_RSP_LEN = 32,
6b208b
+	AUTH_CHAP_RSP_MAX = 32,
6b208b
 };
6b208b
 
6b208b
 /*
6b208b
@@ -61,7 +65,10 @@ enum {
6b208b
 	AUTH_METHOD_MAX_COUNT = 2,
6b208b
 
6b208b
 	AUTH_CHAP_ALG_MD5 = 5,
6b208b
-	AUTH_CHAP_ALG_MAX_COUNT = 2
6b208b
+	AUTH_CHAP_ALG_SHA1 = 6,
6b208b
+	AUTH_CHAP_ALG_SHA256 = 7,
6b208b
+	AUTH_CHAP_ALG_SHA3_256 = 8,
6b208b
+	AUTH_CHAP_ALG_MAX_COUNT = 5
6b208b
 };
6b208b
 
6b208b
 enum auth_neg_role {
6b208b
diff --git a/usr/md5.c b/usr/md5.c
6b208b
deleted file mode 100644
6b208b
index ba6c86d..0000000
6b208b
--- a/usr/md5.c
6b208b
+++ /dev/null
6b208b
@@ -1,236 +0,0 @@
6b208b
-/*
6b208b
- * This code implements the MD5 message-digest algorithm.
6b208b
- * The algorithm is due to Ron Rivest.  This code was
6b208b
- * written by Colin Plumb in 1993, no copyright is claimed.
6b208b
- * This code is in the public domain; do with it what you wish.
6b208b
- *
6b208b
- * Equivalent code is available from RSA Data Security, Inc.
6b208b
- * This code has been tested against that, and is equivalent,
6b208b
- * except that you don't need to include two pages of legalese
6b208b
- * with every copy.
6b208b
- *
6b208b
- * To compute the message digest of a chunk of bytes, declare an
6b208b
- * MD5Context structure, pass it to MD5Init, call MD5Update as
6b208b
- * needed on buffers full of bytes, and then call MD5Final, which
6b208b
- * will fill a supplied 16-byte array with the digest.
6b208b
- *
6b208b
- * Changed so as no longer to depend on Colin Plumb's `usual.h' header
6b208b
- * definitions; now uses stuff from dpkg's config.h.
6b208b
- *  - Ian Jackson <ijackson@nyx.cs.du.edu>.
6b208b
- * Still in the public domain.
6b208b
- */
6b208b
-
6b208b
-#include "md5.h"
6b208b
-
6b208b
-#ifdef WORDS_BIGENDIAN
6b208b
-void
6b208b
-byteSwap(UWORD32 *buf, unsigned words)
6b208b
-{
6b208b
-	md5byte *p = (md5byte *)buf;
6b208b
-
6b208b
-	do {
6b208b
-		*buf++ = (UWORD32)((unsigned)p[3] << 8 | p[2]) << 16 |
6b208b
-			((unsigned)p[1] << 8 | p[0]);
6b208b
-		p += 4;
6b208b
-	} while (--words);
6b208b
-}
6b208b
-#else
6b208b
-#define byteSwap(buf,words)
6b208b
-#endif
6b208b
-
6b208b
-/*
6b208b
- * Start MD5 accumulation.  Set bit count to 0 and buffer to mysterious
6b208b
- * initialization constants.
6b208b
- */
6b208b
-void
6b208b
-MD5Init(struct MD5Context *ctx)
6b208b
-{
6b208b
-	ctx->buf[0] = 0x67452301;
6b208b
-	ctx->buf[1] = 0xefcdab89;
6b208b
-	ctx->buf[2] = 0x98badcfe;
6b208b
-	ctx->buf[3] = 0x10325476;
6b208b
-
6b208b
-	ctx->bytes[0] = 0;
6b208b
-	ctx->bytes[1] = 0;
6b208b
-}
6b208b
-
6b208b
-/*
6b208b
- * Update context to reflect the concatenation of another buffer full
6b208b
- * of bytes.
6b208b
- */
6b208b
-void
6b208b
-MD5Update(struct MD5Context *ctx, md5byte const *buf, unsigned len)
6b208b
-{
6b208b
-	UWORD32 t;
6b208b
-
6b208b
-	/* Update byte count */
6b208b
-
6b208b
-	t = ctx->bytes[0];
6b208b
-	if ((ctx->bytes[0] = t + len) < t)
6b208b
-		ctx->bytes[1]++;	/* Carry from low to high */
6b208b
-
6b208b
-	t = 64 - (t & 0x3f);	/* Space available in ctx->in (at least 1) */
6b208b
-	if (t > len) {
6b208b
-		memcpy((md5byte *)ctx->in + 64 - t, buf, len);
6b208b
-		return;
6b208b
-	}
6b208b
-	/* First chunk is an odd size */
6b208b
-	memcpy((md5byte *)ctx->in + 64 - t, buf, t);
6b208b
-	byteSwap(ctx->in, 16);
6b208b
-	MD5Transform(ctx->buf, ctx->in);
6b208b
-	buf += t;
6b208b
-	len -= t;
6b208b
-
6b208b
-	/* Process data in 64-byte chunks */
6b208b
-	while (len >= 64) {
6b208b
-		memcpy(ctx->in, buf, 64);
6b208b
-		byteSwap(ctx->in, 16);
6b208b
-		MD5Transform(ctx->buf, ctx->in);
6b208b
-		buf += 64;
6b208b
-		len -= 64;
6b208b
-	}
6b208b
-
6b208b
-	/* Handle any remaining bytes of data. */
6b208b
-	memcpy(ctx->in, buf, len);
6b208b
-}
6b208b
-
6b208b
-/*
6b208b
- * Final wrapup - pad to 64-byte boundary with the bit pattern
6b208b
- * 1 0* (64-bit count of bits processed, MSB-first)
6b208b
- */
6b208b
-void
6b208b
-MD5Final(md5byte digest[16], struct MD5Context *ctx)
6b208b
-{
6b208b
-	int count = ctx->bytes[0] & 0x3f;	/* Number of bytes in ctx->in */
6b208b
-	md5byte *p = (md5byte *)ctx->in + count;
6b208b
-
6b208b
-	/* Set the first char of padding to 0x80.  There is always room. */
6b208b
-	*p++ = 0x80;
6b208b
-
6b208b
-	/* Bytes of padding needed to make 56 bytes (-8..55) */
6b208b
-	count = 56 - 1 - count;
6b208b
-
6b208b
-	if (count < 0) {	/* Padding forces an extra block */
6b208b
-		memset(p, 0, count + 8);
6b208b
-		byteSwap(ctx->in, 16);
6b208b
-		MD5Transform(ctx->buf, ctx->in);
6b208b
-		p = (md5byte *)ctx->in;
6b208b
-		count = 56;
6b208b
-	}
6b208b
-	memset(p, 0, count);
6b208b
-	byteSwap(ctx->in, 14);
6b208b
-
6b208b
-	/* Append length in bits and transform */
6b208b
-	ctx->in[14] = ctx->bytes[0] << 3;
6b208b
-	ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29;
6b208b
-	MD5Transform(ctx->buf, ctx->in);
6b208b
-
6b208b
-	byteSwap(ctx->buf, 4);
6b208b
-	memcpy(digest, ctx->buf, 16);
6b208b
-	memset(ctx, 0, sizeof(*ctx));	/* In case it's sensitive */
6b208b
-}
6b208b
-
6b208b
-#ifndef ASM_MD5
6b208b
-
6b208b
-/* The four core functions - F1 is optimized somewhat */
6b208b
-
6b208b
-/* #define F1(x, y, z) (x & y | ~x & z) */
6b208b
-#define F1(x, y, z) (z ^ (x & (y ^ z)))
6b208b
-#define F2(x, y, z) F1(z, x, y)
6b208b
-#define F3(x, y, z) (x ^ y ^ z)
6b208b
-#define F4(x, y, z) (y ^ (x | ~z))
6b208b
-
6b208b
-/* This is the central step in the MD5 algorithm. */
6b208b
-#define MD5STEP(f,w,x,y,z,in,s) \
6b208b
-	 (w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x)
6b208b
-
6b208b
-/*
6b208b
- * The core of the MD5 algorithm, this alters an existing MD5 hash to
6b208b
- * reflect the addition of 16 longwords of new data.  MD5Update blocks
6b208b
- * the data and converts bytes into longwords for this routine.
6b208b
- */
6b208b
-void
6b208b
-MD5Transform(UWORD32 buf[4], UWORD32 const in[16])
6b208b
-{
6b208b
-	register UWORD32 a, b, c, d;
6b208b
-
6b208b
-	a = buf[0];
6b208b
-	b = buf[1];
6b208b
-	c = buf[2];
6b208b
-	d = buf[3];
6b208b
-
6b208b
-	MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
6b208b
-	MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
6b208b
-	MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
6b208b
-	MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
6b208b
-	MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
6b208b
-	MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
6b208b
-	MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
6b208b
-	MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
6b208b
-	MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
6b208b
-	MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
6b208b
-	MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
6b208b
-	MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
6b208b
-	MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
6b208b
-	MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
6b208b
-	MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
6b208b
-	MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
6b208b
-
6b208b
-	MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
6b208b
-	MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
6b208b
-	MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
6b208b
-	MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
6b208b
-	MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
6b208b
-	MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
6b208b
-	MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
6b208b
-	MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
6b208b
-	MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
6b208b
-	MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
6b208b
-	MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
6b208b
-	MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
6b208b
-	MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
6b208b
-	MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
6b208b
-	MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
6b208b
-	MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
6b208b
-
6b208b
-	MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
6b208b
-	MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
6b208b
-	MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
6b208b
-	MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
6b208b
-	MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
6b208b
-	MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
6b208b
-	MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
6b208b
-	MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
6b208b
-	MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
6b208b
-	MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
6b208b
-	MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
6b208b
-	MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
6b208b
-	MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
6b208b
-	MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
6b208b
-	MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
6b208b
-	MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
6b208b
-
6b208b
-	MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
6b208b
-	MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
6b208b
-	MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
6b208b
-	MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
6b208b
-	MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
6b208b
-	MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
6b208b
-	MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
6b208b
-	MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
6b208b
-	MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
6b208b
-	MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
6b208b
-	MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
6b208b
-	MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
6b208b
-	MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
6b208b
-	MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
6b208b
-	MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
6b208b
-	MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
6b208b
-
6b208b
-	buf[0] += a;
6b208b
-	buf[1] += b;
6b208b
-	buf[2] += c;
6b208b
-	buf[3] += d;
6b208b
-}
6b208b
-
6b208b
-#endif
6b208b
diff --git a/usr/md5.h b/usr/md5.h
6b208b
deleted file mode 100644
6b208b
index 100eecc..0000000
6b208b
--- a/usr/md5.h
6b208b
+++ /dev/null
6b208b
@@ -1,60 +0,0 @@
6b208b
-/*
6b208b
- * This is the header file for the MD5 message-digest algorithm.
6b208b
- * The algorithm is due to Ron Rivest.  This code was
6b208b
- * written by Colin Plumb in 1993, no copyright is claimed.
6b208b
- * This code is in the public domain; do with it what you wish.
6b208b
- *
6b208b
- * Equivalent code is available from RSA Data Security, Inc.
6b208b
- * This code has been tested against that, and is equivalent,
6b208b
- * except that you don't need to include two pages of legalese
6b208b
- * with every copy.
6b208b
- *
6b208b
- * To compute the message digest of a chunk of bytes, declare an
6b208b
- * MD5Context structure, pass it to MD5Init, call MD5Update as
6b208b
- * needed on buffers full of bytes, and then call MD5Final, which
6b208b
- * will fill a supplied 16-byte array with the digest.
6b208b
- *
6b208b
- * Changed so as no longer to depend on Colin Plumb's `usual.h'
6b208b
- * header definitions; now uses stuff from dpkg's config.h
6b208b
- *  - Ian Jackson <ijackson@nyx.cs.du.edu>.
6b208b
- * Still in the public domain.
6b208b
- */
6b208b
-
6b208b
-#ifndef MD5_H
6b208b
-#define MD5_H
6b208b
-
6b208b
-#include <string.h>
6b208b
-#include <sys/types.h>
6b208b
-#include <netinet/in.h>
6b208b
-#include <stdint.h>
6b208b
-#if (__BYTE_ORDER == __BIG_ENDIAN)
6b208b
-#  define WORDS_BIGENDIAN 1
6b208b
-#endif
6b208b
-
6b208b
-typedef uint32_t UWORD32;
6b208b
-
6b208b
-
6b208b
-#ifdef __cplusplus
6b208b
-extern "C" {
6b208b
-#endif
6b208b
-
6b208b
-
6b208b
-#define md5byte unsigned char
6b208b
-
6b208b
-struct MD5Context {
6b208b
-	UWORD32 buf[4];
6b208b
-	UWORD32 bytes[2];
6b208b
-	UWORD32 in[16];
6b208b
-};
6b208b
-
6b208b
-void MD5Init(struct MD5Context *context);
6b208b
-void MD5Update(struct MD5Context *context, md5byte const *buf, unsigned len);
6b208b
-void MD5Final(unsigned char digest[16], struct MD5Context *context);
6b208b
-void MD5Transform(UWORD32 buf[4], UWORD32 const in[16]);
6b208b
-
6b208b
-
6b208b
-#ifdef __cplusplus
6b208b
-}
6b208b
-#endif
6b208b
-
6b208b
-#endif /* !MD5_H */
6b208b
diff --git a/usr/sha1.c b/usr/sha1.c
6b208b
deleted file mode 100644
6b208b
index 8285a5e..0000000
6b208b
--- a/usr/sha1.c
6b208b
+++ /dev/null
6b208b
@@ -1,167 +0,0 @@
6b208b
-/*
6b208b
- * Cryptographic API.
6b208b
- *
6b208b
- * SHA1 Secure Hash Algorithm.
6b208b
- *
6b208b
- * Derived from cryptoapi implementation, adapted for in-place
6b208b
- * scatterlist interface.  Originally based on the public domain
6b208b
- * implementation written by Steve Reid.
6b208b
- *
6b208b
- * Copyright (c) Alan Smithee.
6b208b
- * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk>
6b208b
- * Copyright (c) Jean-Francois Dive <jef@linuxbe.org>
6b208b
- *
6b208b
- * This program is free software; you can redistribute it and/or modify it
6b208b
- * under the terms of the GNU General Public License as published by the Free
6b208b
- * Software Foundation; either version 2 of the License, or (at your option)
6b208b
- * any later version.
6b208b
- *
6b208b
- */
6b208b
-#include "sha1.h"
6b208b
-
6b208b
-#define SHA1_DIGEST_SIZE	20
6b208b
-#define SHA1_HMAC_BLOCK_SIZE	64
6b208b
-
6b208b
-static inline uint32_t rol(uint32_t value, uint32_t bits)
6b208b
-{
6b208b
-	return (((value) << (bits)) | ((value) >> (32 - (bits))));
6b208b
-}
6b208b
-
6b208b
-/* blk0() and blk() perform the initial expand. */
6b208b
-/* I got the idea of expanding during the round function from SSLeay */
6b208b
-# define blk0(i) block32[i]
6b208b
-
6b208b
-#define blk(i) (block32[i&15] = rol(block32[(i+13)&15]^block32[(i+8)&15] \
6b208b
-    ^block32[(i+2)&15]^block32[i&15],1))
6b208b
-
6b208b
-/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
6b208b
-#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5); \
6b208b
-                        w=rol(w,30);
6b208b
-#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5); \
6b208b
-                        w=rol(w,30);
6b208b
-#define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30);
6b208b
-#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5); \
6b208b
-                        w=rol(w,30);
6b208b
-#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);
6b208b
-
6b208b
-/* Hash a single 512-bit block. This is the core of the algorithm. */
6b208b
-static void sha1_transform(uint32_t *state, const uint8_t *in)
6b208b
-{
6b208b
-	uint32_t a, b, c, d, e;
6b208b
-	uint32_t block32[16];
6b208b
-
6b208b
-	/* convert/copy data to workspace */
6b208b
-	for (a = 0; a < sizeof(block32)/sizeof(uint32_t); a++)
6b208b
-	  block32[a] = ntohl (((const uint32_t *)in)[a]);
6b208b
-
6b208b
-	/* Copy context->state[] to working vars */
6b208b
-	a = state[0];
6b208b
-	b = state[1];
6b208b
-	c = state[2];
6b208b
-	d = state[3];
6b208b
-	e = state[4];
6b208b
-
6b208b
-	/* 4 rounds of 20 operations each. Loop unrolled. */
6b208b
-	R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
6b208b
-	R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
6b208b
-	R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
6b208b
-	R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
6b208b
-	R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
6b208b
-	R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
6b208b
-	R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
6b208b
-	R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
6b208b
-	R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
6b208b
-	R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
6b208b
-	R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
6b208b
-	R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
6b208b
-	R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
6b208b
-	R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
6b208b
-	R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
6b208b
-	R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
6b208b
-	R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
6b208b
-	R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
6b208b
-	R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
6b208b
-	R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
6b208b
-	/* Add the working vars back into context.state[] */
6b208b
-	state[0] += a;
6b208b
-	state[1] += b;
6b208b
-	state[2] += c;
6b208b
-	state[3] += d;
6b208b
-	state[4] += e;
6b208b
-	/* Wipe variables */
6b208b
-	a = b = c = d = e = 0;
6b208b
-	memset (block32, 0x00, sizeof block32);
6b208b
-}
6b208b
-
6b208b
-void sha1_init(void *ctx)
6b208b
-{
6b208b
-	struct sha1_ctx *sctx = ctx;
6b208b
-	static const struct sha1_ctx initstate = {
6b208b
-	  0,
6b208b
-	  { 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0 },
6b208b
-	  { 0, }
6b208b
-	};
6b208b
-
6b208b
-	*sctx = initstate;
6b208b
-}
6b208b
-
6b208b
-void sha1_update(void *ctx, const uint8_t *data, unsigned int len)
6b208b
-{
6b208b
-	struct sha1_ctx *sctx = ctx;
6b208b
-	unsigned int i, j;
6b208b
-
6b208b
-	j = (sctx->count >> 3) & 0x3f;
6b208b
-	sctx->count += len << 3;
6b208b
-
6b208b
-	if ((j + len) > 63) {
6b208b
-		memcpy(&sctx->buffer[j], data, (i = 64-j));
6b208b
-		sha1_transform(sctx->state, sctx->buffer);
6b208b
-		for ( ; i + 63 < len; i += 64) {
6b208b
-			sha1_transform(sctx->state, &data[i]);
6b208b
-		}
6b208b
-		j = 0;
6b208b
-	}
6b208b
-	else i = 0;
6b208b
-	memcpy(&sctx->buffer[j], &data[i], len - i);
6b208b
-}
6b208b
-
6b208b
-
6b208b
-/* Add padding and return the message digest. */
6b208b
-void sha1_final(void* ctx, uint8_t *out)
6b208b
-{
6b208b
-	struct sha1_ctx *sctx = ctx;
6b208b
-	uint32_t i, j, index, padlen;
6b208b
-	uint64_t t;
6b208b
-	uint8_t bits[8] = { 0, };
6b208b
-	static const uint8_t padding[64] = { 0x80, };
6b208b
-
6b208b
-	t = sctx->count;
6b208b
-	bits[7] = 0xff & t; t>>=8;
6b208b
-	bits[6] = 0xff & t; t>>=8;
6b208b
-	bits[5] = 0xff & t; t>>=8;
6b208b
-	bits[4] = 0xff & t; t>>=8;
6b208b
-	bits[3] = 0xff & t; t>>=8;
6b208b
-	bits[2] = 0xff & t; t>>=8;
6b208b
-	bits[1] = 0xff & t; t>>=8;
6b208b
-	bits[0] = 0xff & t;
6b208b
-
6b208b
-	/* Pad out to 56 mod 64 */
6b208b
-	index = (sctx->count >> 3) & 0x3f;
6b208b
-	padlen = (index < 56) ? (56 - index) : ((64+56) - index);
6b208b
-	sha1_update(sctx, padding, padlen);
6b208b
-
6b208b
-	/* Append length */
6b208b
-	sha1_update(sctx, bits, sizeof bits);
6b208b
-
6b208b
-	/* Store state in digest */
6b208b
-	for (i = j = 0; i < 5; i++, j += 4) {
6b208b
-		uint32_t t2 = sctx->state[i];
6b208b
-		out[j+3] = t2 & 0xff; t2>>=8;
6b208b
-		out[j+2] = t2 & 0xff; t2>>=8;
6b208b
-		out[j+1] = t2 & 0xff; t2>>=8;
6b208b
-		out[j  ] = t2 & 0xff;
6b208b
-	}
6b208b
-
6b208b
-	/* Wipe context */
6b208b
-	memset(sctx, 0, sizeof *sctx);
6b208b
-}
6b208b
diff --git a/usr/sha1.h b/usr/sha1.h
6b208b
deleted file mode 100644
6b208b
index af436b3..0000000
6b208b
--- a/usr/sha1.h
6b208b
+++ /dev/null
6b208b
@@ -1,27 +0,0 @@
6b208b
-/*
6b208b
- * sha1.h - SHA1 Secure Hash Algorithm used for CHAP authentication.
6b208b
- * copied from the Linux kernel's Cryptographic API and slightly adjusted to
6b208b
- * fit IET's needs
6b208b
- *
6b208b
- * This file is (c) 2004 Xiranet Communications GmbH <arne.redlich@xiranet.com>
6b208b
- * and licensed under the GPL.
6b208b
- */
6b208b
-
6b208b
-#ifndef SHA1_H
6b208b
-#define SHA1_H
6b208b
-
6b208b
-#include <sys/types.h>
6b208b
-#include <string.h>
6b208b
-#include "types.h"
6b208b
-
6b208b
-struct sha1_ctx {
6b208b
-        uint64_t count;
6b208b
-        uint32_t state[5];
6b208b
-        uint8_t buffer[64];
6b208b
-};
6b208b
-
6b208b
-void sha1_init(void *ctx);
6b208b
-void sha1_update(void *ctx, const uint8_t *data, unsigned int len);
6b208b
-void sha1_final(void* ctx, uint8_t *out);
6b208b
-
6b208b
-#endif
6b208b
-- 
6b208b
2.21.3
6b208b