Giter Site home page Giter Site logo

patrickfav / hkdf Goto Github PK

View Code? Open in Web Editor NEW
63.0 4.0 9.0 2.83 MB

A standalone Java 7 implementation of HMAC-based key derivation function (HKDF) defined in RFC 5869 first described by Hugo Krawczyk. HKDF follows the "extract-then-expand" paradigm which is compatible to NIST 800-56C Rev. 1 two step KDF

Home Page: https://favr.dev/opensource/hkdf

License: Apache License 2.0

Java 100.00%
hkdf kdf hmac hmac-sha256 rfc5869 hash cryptography hmac-sha512 java7 android-compatibility

hkdf's People

Contributors

alisianoi avatar dependabot[bot] avatar overheadhunter avatar patrickfav avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

hkdf's Issues

Add `module-info.java`

Hi,

There hasn't been much activity in this repo for some time, so I hope you're still involved.

I'd like to request to make this a modular jar, as downstream projects would benefit from it.

Using multi-release jars, it is possible to do so while staying compatible with the pre-java 9 world (including Android). I've done this multiple times myself and would like to help out with a PR. However, I don't really know if you're using Maven or Gradle to build this lib, as the repo contains both.

Cheers!

Bump Java target to 8

I believe the current state of the code is stable enough to keep it as-is. It would make sense to create a Java 8 version as a first step to migrate to Java 9+

InputKeyingMaterial should be provided as SecretKey, not (only) as byte array

In order to provide compatibility with HSM, the input keying material should be directly provided as SecretKey.

At the moment, you recreate a SecretKey from a byte array, and provide it to the mac instance.

Whereas you should also provide a signature where we can provide a SecretKey which already contain the keying material.

This is preferred to keep compatibility with HSM, the input keying material is not always "readable" depending of the source of the keying material.

This also mean that the keying material should comes from the same source as the mac instance you are generating, but this is already covered by the fact you allow to provide the mac provider.

Different result than with WolfSSL

Hi, first of all, great job !!

I am interfacing with a C program which uses WolfSSL, but I obtain different result with the same inputs:
The C code:

#define HashDefinitions_HashType__HASH_TYPE_SHA512 5

int32_t main(int32_t argc, char *(argv[])) 
{
  uint8_t salt[32] = {
    0x10u,    0x20u,    0x30u,    0x40u,    0x50u,    0x60u,    0x70u,    0x80u,    0x90u,    0x93u,    0x96u,
    0x11u,    0x21u,    0x31u,    0x41u,    0x51u,    0x61u,    0x71u,    0x81u,    0x91u,    0x94u,    0x97u,
    0x12u,    0x22u,    0x32u,    0x42u,    0x52u,    0x62u,    0x72u,    0x82u,    0x92u,    0x95u  };
  
  uint8_t sharedSecret[32] = {
    0xE8u,    0xEDu,    0x47u,    0xCEu,    0x79u,    0x3Fu,    0x6Bu,    0xE8u,    0x5Du,    0xF5u,    0x96u,
    0xB6u,    0x59u,    0xB1u,    0x7Au,    0x0Eu,    0x0Au,    0xB7u,    0xD5u,    0xCCu,    0x43u,    0xDCu,
    0x45u,    0x49u,    0x2Cu,    0xC6u,    0x97u,    0x05u,    0x75u,    0xC3u,    0xB3u,    0x68u  };
  uint8_t derivedKey1[32];
  int32_t ret = wc_HKDF(HashDefinitions_HashType__HASH_TYPE_SHA512, sharedSecret, sizeof(sharedSecret), salt, sizeof(salt), NULL, 0, derivedKey1, 32);
  Main_printData("Result", derivedKey1, 32);
  // Result: b7986122a3974da0bdb542f8a5df6ec2b2d45bfcbf9c67bef1188d764cc9066d
  return ret;
}


void Main_printData(char *msg, uint8_t *data, uint32_t len) 
{
  printf(msg);
  printf(": ");
  for ( int64_t __i = 0 ; __i < len; __i++ )
  {
    printf("%02x", data[__i]);
  }
  printf("\n");
  
}

And my Kotlin program (sorry it's not Java, but it is almost the same)

fun main(args: Array<String>) {
        val salt=ByteUtil.byteArrayOfInts(0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x80,0x90,0x93,0x96,0x11,
            0x21,0x31,0x41,0x51,0x61,0x71,0x81,0x91,0x94,0x97,0x12,0x22,0x32,0x42,0x52,0x62,0x72,0x82,0x92,0x95);
        val sharedSecret =ByteUtil.byteArrayOfInts(0xE8, 0xED, 0x47, 0xCE, 0x79, 0x3F, 0x6B, 0xE8, 0x5D,
            0xF5, 0x96, 0xB6, 0x59, 0xB1, 0x7A, 0x0E, 0x0A, 0xB7, 0xD5, 0xCC, 0x43, 0xDC, 0x45, 0x49, 0x2C, 0xC6, 0x97,
            0x05, 0x75, 0xC3, 0xB3, 0x68
        );
        println("Salt: "+format(salt));
        println("Shared Secret: "+format(sharedSecret));
        val hkdf = HKDF.fromHmacSha512();
        val pseudoRandomKey = hkdf.extract(salt, sharedSecret)
        val expand = hkdf.expand(pseudoRandomKey, null, 32)
        println("Derived   Key 1: " + format(expand));
        // Result is 1b01b30e3afb8369a7be2c3362dac46185ee7d0c4494a66770d49d424e6b8fa8
}

fun format(ba: ByteArray): String {
        return ba.joinToString("") { String.format("%02x", it) };
    }

Am I missing something there? Is it something that deals with indianness or displaying values? Or is there some difference in the implementation which doesn't matter in the end?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.