Beispiel #1
0
// Generates an RSA private key and computes the corresponding 64-bit
// Id for it, using Id=Fold(Sha256(Rsa64(PublicKey)))
//
// TODO:
//   (*) Decide on default signature key size
//   (*) Allow custom-size private keys, and/or
func GenerateSigKey() *SigKey {
	randr := crypto.NewTimedRand()
	rsapriv, err := rsa.GenerateKey(randr, SignatureModulusLen*8)
	if err != nil {
		panic("unable to generate RSA key")
	}
	return &SigKey{rsapriv}
}
Beispiel #2
0
func GenerateSigChallange() []byte {
	urand := crypto.NewTimedRand()
	ch := make([]byte, 20) // we are using SHA1 hash for RSA signature
	n, err := urand.Read(ch)
	if err != nil || n != len(ch) {
		panic("sys, chall")
	}
	return ch
}
Beispiel #3
0
func GenerateKeyHalves() *KeyHalves {
	urand := crypto.NewTimedRand()
	kh := &KeyHalves{}
	kh.bothKeys = make([]byte, KeyHalvesLen)
	n, _ := urand.Read(kh.bothKeys)
	if n != len(kh.bothKeys) {
		panic("d")
	}
	return kh
}
Beispiel #4
0
func (sk *SigKey) Sign(msg []byte) ([]byte, os.Error) {
	// Hash the message
	hash := sha1.New()
	n, err := hash.Write(msg)
	if err != nil || n != len(msg) {
		return nil, err
	}
	hashed := hash.Sum()

	// Sign the message
	urand := crypto.NewTimedRand()
	s, err := rsa.SignPKCS1v15(urand, sk.RsaPrivKey(), rsa.HashSHA1, hashed)
	if err != nil {
		return nil, err
	}

	return s, nil
}
Beispiel #5
0
func GenerateDialKey() *DialKey {
	rand := crypto.NewTimedRand()
	dk := DialKey(rand.Int63())
	return &dk
}