// GenerateKey generates a lamport key-pair.
//
// It is suggested to use the crypto/rand reader.
// A classic lamport key would be generated using crypto.SHA256.
//
// Will panic if the hash function is not linked into the binary.
GenerateKey generates a lamport key-pair.

It is suggested to use the crypto/rand reader.
A classic lamport key would be generated using crypto.SHA256.

Will panic if the hash function is not linked into the binary.
// GenerateKey generates a lamport key - pair . // // It is suggested to use the crypto / rand reader . // A classic lamport key would be generated using crypto . SHA256 . // // Will panic if the hash function is not linked into the binary .
func GenerateKey(random io.Reader, h crypto.Hash) (*PrivateKey, error) {
	hash := h.New()
	hashSize := hash.Size()
	keySize := 16 * hashSize * hashSize
	keyBytes := make([]byte, keySize)
	n, err := random.Read(keyBytes)
	if err != nil {
		return nil, fmt.Errorf("lamport: %s", err)
	}
	if n != keySize {
		return nil, fmt.Errorf("lamport: not enough entropy")
	}
	blocksSize := keySize / 2
	LBlocks := keyBytes[:blocksSize]
	RBlocks := keyBytes[blocksSize:]
	LBlocksP := make([]byte, 0, blocksSize)
	RBlocksP := make([]byte, 0, blocksSize)
	for off := 0; off < blocksSize; off += hashSize {
		hash.Write(LBlocks[off : off+hashSize]) 
		LBlocksP = append(LBlocksP, hash.Sum(nil)...)
		hash.Reset()
		hash.Write(RBlocks[off : off+hashSize]) 
		RBlocksP = append(RBlocksP, hash.Sum(nil)...)
		hash.Reset()
	}
	pk := PublicKey{
		Hash:     h,
		LBlocksP: LBlocksP,
		RBlocksP: RBlocksP,
	}
	k := &PrivateKey{
		PublicKey: pk,
		LBlocks: LBlocks,
		RBlocks: RBlocks,
	}
	return k, nil
}
func GenerateKey ( random io . Reader , h crypto . Hash ) ( * PrivateKey , error ) { hash := h . New ( ) hashSize := hash . Size ( ) keySize := 16 * hashSize * hashSize keyBytes := make ( [ ] byte , keySize ) n , err := random . Read ( keyBytes ) if err != nil { return nil , fmt . Errorf ( " " , err ) } if n != keySize { return nil , fmt . Errorf ( " " ) } blocksSize := keySize / 2 LBlocks := keyBytes [ : blocksSize ] RBlocks := keyBytes [ blocksSize : ] LBlocksP := make ( [ ] byte , 0 , blocksSize ) RBlocksP := make ( [ ] byte , 0 , blocksSize ) for off := 0 ; off < blocksSize ; off += hashSize { hash . Write ( LBlocks [ off : off + hashSize ] ) LBlocksP = append ( LBlocksP , hash . Sum ( nil ) ... ) hash . Reset ( ) hash . Write ( RBlocks [ off : off + hashSize ] ) RBlocksP = append ( RBlocksP , hash . Sum ( nil ) ... ) hash . Reset ( ) } pk := PublicKey { Hash : h , LBlocksP : LBlocksP , RBlocksP : RBlocksP , } k := & PrivateKey { PublicKey : pk , LBlocks : LBlocks , RBlocks : RBlocks , } return k , nil }
GenerateKey generates a lamport key-pair.
GenerateKey generates a lamport key - pair .
// panic immediately if hash not linked // nolint, error always nil // nolint, error always nil