Browse Source

add libkcapi-enc patch from old buildroot

Huan.Feng 3 years ago
parent
commit
907939eb07
1 changed files with 83 additions and 0 deletions
  1. 83 0
      package/libkcapi/0001-kcapi-enc.patch

+ 83 - 0
package/libkcapi/0001-kcapi-enc.patch

@@ -0,0 +1,83 @@
+diff -Nurp libkcapi-1.2.0/apps/kcapi-enc.c libkcapi-1.2.0_new/apps/kcapi-enc.c
+--- libkcapi-1.2.0/apps/kcapi-enc.c	2020-05-25 04:09:52.000000000 +0800
++++ libkcapi-1.2.0_new/apps/kcapi-enc.c	2020-10-14 09:27:20.123051459 +0800
+@@ -727,77 +727,10 @@ static int set_key(struct kcapi_handle *
+ 
+ 	/* Transform password into a key using PBKDF2. */
+ 	if (passwdptr && passwdlen) {
+-		uint8_t *saltbuf = NULL;
+-		uint32_t saltbuflen = 0;
+-
+-		dolog(KCAPI_LOG_DEBUG, "password %s", passwdptr);
+-
+-		/* Determine the number of PBKDF2 iterations. */
+-		if (!opts->pbkdf_iterations) {
+-			opts->pbkdf_iterations =
+-			     kcapi_pbkdf_iteration_count(opts->pbkdf_hash, 0);
+-
+-			dolog(KCAPI_LOG_WARN, "PBKDF2 iterations used: %u",
+-			      opts->pbkdf_iterations);
+-		}
+-
+-		/* Convert the salt hex representation into binary. */
+-		if (opts->salt) {
+-			ret = hex2bin_alloc(opts->salt, strlen(opts->salt),
+-					    &saltbuf, &saltbuflen);
+-			if (ret)
+-				goto out;
+-		} else {
+-			/* No salt provided, generate a random number. */
+-			struct kcapi_handle *rng;
+-			uint32_t j = 0;
+-
+-			ret = kcapi_rng_init(&rng, "stdrng", 0);
+-			if (ret)
+-				goto out;
+-			ret = kcapi_rng_seed(rng, NULL, 0);
+-			if (ret) {
+-				kcapi_rng_destroy(rng);
+-				goto out;
+-			}
+-
+-			saltbuflen = 32;
+-			saltbuf = malloc(saltbuflen);
+-			if (!saltbuf) {
+-				ret = -ENOMEM;
+-				kcapi_rng_destroy(rng);
+-				goto out;
+-			}
+-
+-			while (j < saltbuflen) {
+-				ret = kcapi_rng_generate(rng, saltbuf,
+-							 saltbuflen);
+-				if (ret < 0) {
+-					kcapi_rng_destroy(rng);
+-					free(saltbuf);
+-					goto out;
+-				}
+-				j += (uint32_t)ret;
+-			}
+-			kcapi_rng_destroy(rng);
+-
+-			dolog_bin(KCAPI_LOG_WARN, saltbuf, saltbuflen,
+-				  "PBKDF2 salt used");
+-		}
+-
+-		/*
+-		 * PBKDF2 operation: generate a key from password --
+-		 * reading of sizeof(keybuf) implies 256 bit key.
+-		*/
+-		ret = kcapi_pbkdf(opts->pbkdf_hash, passwdptr, passwdlen,
+-				  saltbuf, saltbuflen, opts->pbkdf_iterations,
+-				  keybuf, sizeof(keybuf));
+-		free(saltbuf);
+-		if (ret)
+-			goto out;
+ 
+ 		have_key = 1;
+-		keybuflen = sizeof(keybuf);
++		memcpy(keybuf,passwdptr,passwdlen);
++		keybuflen = passwdlen;
+ 
+ 		dolog(KCAPI_LOG_VERBOSE,
+ 		      "Data Encryption Key derived from Password using PBKDF2 using %s with %u iterations",