Sha256: 1d3d81009f4626ea74356fe12048f632f13a31c75f3ee4be2f15ae11677aab20

Contents?: true

Size: 1.06 KB

Versions: 16

Compression:

Stored size: 1.06 KB

Contents

package kdf

import (
	"hash"
	"math"
	"github.com/dvsekhvalnov/jose2go/arrays"
)

const (
	MaxInt = int(^uint(0)>>1);
)

// DeriveConcatKDF implements NIST SP 800-56A Concatenation Key Derivation Function. Derives 
// key material of keydatalen bits size given Z (sharedSecret), OtherInfo (AlgorithmID | 
// PartyUInfo | PartyVInfo | SuppPubInfo | SuppPrivInfo) and hash function
func DeriveConcatKDF(keydatalen int, sharedSecret, algId, partyUInfo, partyVInfo, suppPubInfo, suppPrivInfo []byte, h hash.Hash) []byte {
	
	otherInfo := arrays.Concat(algId, partyUInfo, partyVInfo, suppPubInfo, suppPrivInfo)
	
	keyLenBytes := keydatalen >> 3
	
	reps := int(math.Ceil(float64(keyLenBytes) / float64(h.Size())))
	
	if reps > MaxInt {
		panic("kdf.DeriveConcatKDF: too much iterations (more than 2^32-1).")
	}
	
	dk:=make([]byte, 0, keyLenBytes)
	
	for counter := 1;counter <= reps;counter++ {
		h.Reset()

		counterBytes:=arrays.UInt32ToBytes(uint32(counter))
						
		h.Write(counterBytes)
		h.Write(sharedSecret)		
		h.Write(otherInfo)
		
		dk = h.Sum(dk)
	}

	return dk[:keyLenBytes]	
}

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ruby_snowflake_client-1.3.7 ext/vendor/github.com/dvsekhvalnov/jose2go/kdf/nist_sp800_56a.go
ruby_snowflake_client-1.3.6 ext/vendor/github.com/dvsekhvalnov/jose2go/kdf/nist_sp800_56a.go
ruby_snowflake_client-1.3.5 ext/vendor/github.com/dvsekhvalnov/jose2go/kdf/nist_sp800_56a.go
ruby_snowflake_client-1.3.4 ext/vendor/github.com/dvsekhvalnov/jose2go/kdf/nist_sp800_56a.go
ruby_snowflake_client-1.3.4.pre.debug ext/vendor/github.com/dvsekhvalnov/jose2go/kdf/nist_sp800_56a.go
ruby_snowflake_client-1.3.3.pre.debug ext/vendor/github.com/dvsekhvalnov/jose2go/kdf/nist_sp800_56a.go
ruby_snowflake_client-1.3.2 ext/vendor/github.com/dvsekhvalnov/jose2go/kdf/nist_sp800_56a.go
ruby_snowflake_client-1.3.1 ext/vendor/github.com/dvsekhvalnov/jose2go/kdf/nist_sp800_56a.go
ruby_snowflake_client-1.3.0 ext/vendor/github.com/dvsekhvalnov/jose2go/kdf/nist_sp800_56a.go
ruby_snowflake_client-1.2.1 ext/vendor/github.com/dvsekhvalnov/jose2go/kdf/nist_sp800_56a.go
ruby_snowflake_client-1.2.0 ext/vendor/github.com/dvsekhvalnov/jose2go/kdf/nist_sp800_56a.go
ruby_snowflake_client-1.1.1 ext/vendor/github.com/dvsekhvalnov/jose2go/kdf/nist_sp800_56a.go
ruby_snowflake_client-1.1.0 ext/vendor/github.com/dvsekhvalnov/jose2go/kdf/nist_sp800_56a.go
ruby_snowflake_client-1.0.2 ext/vendor/github.com/dvsekhvalnov/jose2go/kdf/nist_sp800_56a.go
ruby_snowflake_client-1.0.1 ext/vendor/github.com/dvsekhvalnov/jose2go/kdf/nist_sp800_56a.go
ruby_snowflake_client-1.0.0 ext/vendor/github.com/dvsekhvalnov/jose2go/kdf/nist_sp800_56a.go