Jonathan Turner 8 лет назад
Родитель
Сommit
506147e9fa

+ 1 - 2
crypto/aes128-cts-hmac-sha1-96_test.go

@@ -5,7 +5,6 @@ import (
 	"github.com/stretchr/testify/assert"
 	"gopkg.in/jcmturner/gokrb5.v2/crypto/common"
 	"gopkg.in/jcmturner/gokrb5.v2/crypto/rfc3962"
-	"math/big"
 	"testing"
 )
 
@@ -33,7 +32,7 @@ func TestAes128CtsHmacSha196_StringToKey(t *testing.T) {
 	var e Aes128CtsHmacSha96
 	for i, test := range tests {
 
-		assert.Equal(t, test.pbkdf2, hex.EncodeToString(rfc3962.StringToPBKDF2(test.phrase, test.salt, big.NewInt(test.iterations), e)), "PBKDF2 not as expected")
+		assert.Equal(t, test.pbkdf2, hex.EncodeToString(rfc3962.StringToPBKDF2(test.phrase, test.salt, test.iterations, e)), "PBKDF2 not as expected")
 		k, err := e.StringToKey(test.phrase, test.salt, common.IterationsToS2Kparams(uint32(test.iterations)))
 		if err != nil {
 			t.Errorf("Error in processing string to key for test %d: %v", i, err)

+ 1 - 2
crypto/aes256-cts-hmac-sha1-96_test.go

@@ -5,7 +5,6 @@ import (
 	"github.com/stretchr/testify/assert"
 	"gopkg.in/jcmturner/gokrb5.v2/crypto/common"
 	"gopkg.in/jcmturner/gokrb5.v2/crypto/rfc3962"
-	"math/big"
 	"testing"
 )
 
@@ -33,7 +32,7 @@ func TestAes256CtsHmacSha196_StringToKey(t *testing.T) {
 	var e Aes256CtsHmacSha96
 	for i, test := range tests {
 
-		assert.Equal(t, test.pbkdf2, hex.EncodeToString(rfc3962.StringToPBKDF2(test.phrase, test.salt, big.NewInt(test.iterations), e)), "PBKDF2 not as expected")
+		assert.Equal(t, test.pbkdf2, hex.EncodeToString(rfc3962.StringToPBKDF2(test.phrase, test.salt, test.iterations, e)), "PBKDF2 not as expected")
 		k, err := e.StringToKey(test.phrase, test.salt, common.IterationsToS2Kparams(uint32(test.iterations)))
 		if err != nil {
 			t.Errorf("Error in processing string to key for test %d: %v", i, err)

+ 8 - 13
crypto/rfc3962/keyDerivation.go

@@ -6,7 +6,6 @@ import (
 	"errors"
 	"github.com/jcmturner/gofork/x/crypto/pbkdf2"
 	"gopkg.in/jcmturner/gokrb5.v2/crypto/etype"
-	"math/big"
 )
 
 const (
@@ -23,18 +22,18 @@ func StringToKey(secret, salt, s2kparams string, e etype.EType) ([]byte, error)
 }
 
 // StringToPBKDF2 generates an encryption key from a pass phrase and salt string using the PBKDF2 function from PKCS #5 v2.0
-func StringToPBKDF2(secret, salt string, iterations *big.Int, e etype.EType) []byte {
-	return pbkdf2.KeyBigIter([]byte(secret), []byte(salt), iterations, e.GetKeyByteSize(), e.GetHashFunc())
+func StringToPBKDF2(secret, salt string, iterations int64, e etype.EType) []byte {
+	return pbkdf2.Key64([]byte(secret), []byte(salt), iterations, int64(e.GetKeyByteSize()), e.GetHashFunc())
 }
 
 // StringToKeyIter returns a key derived from the string provided according to the definition in RFC 3961.
-func StringToKeyIter(secret, salt string, iterations *big.Int, e etype.EType) ([]byte, error) {
+func StringToKeyIter(secret, salt string, iterations int64, e etype.EType) ([]byte, error) {
 	tkey := e.RandomToKey(StringToPBKDF2(secret, salt, iterations, e))
 	return e.DeriveKey(tkey, []byte("kerberos"))
 }
 
 // S2KparamsToItertions converts the string representation of iterations to an integer
-func S2KparamsToItertions(s2kparams string) (*big.Int, error) {
+func S2KparamsToItertions(s2kparams string) (int64, error) {
 	//process s2kparams string
 	//The parameter string is four octets indicating an unsigned
 	//number in big-endian order.  This is the number of iterations to be
@@ -42,21 +41,17 @@ func S2KparamsToItertions(s2kparams string) (*big.Int, error) {
 	//be performed is 4,294,967,296 (2**32).
 	var i uint32
 	if len(s2kparams) != 8 {
-		i := big.NewInt(s2kParamsZero)
-		return i, errors.New("invalid s2kparams length")
+		return int64(s2kParamsZero), errors.New("invalid s2kparams length")
 	}
 	b, err := hex.DecodeString(s2kparams)
 	if err != nil {
-		i := big.NewInt(s2kParamsZero)
-		return i, errors.New("invalid s2kparams, cannot decode string to bytes")
+		return int64(s2kParamsZero), errors.New("invalid s2kparams, cannot decode string to bytes")
 	}
 	i = binary.BigEndian.Uint32(b)
 	//buf := bytes.NewBuffer(b)
 	//err = binary.Read(buf, binary.BigEndian, &i)
 	if err != nil {
-		i := big.NewInt(s2kParamsZero)
-		return i, errors.New("invalid s2kparams, cannot convert to big endian int32")
+		return int64(s2kParamsZero), errors.New("invalid s2kparams, cannot convert to big endian int32")
 	}
-	bigi := big.NewInt(int64(i))
-	return bigi, nil
+	return int64(i), nil
 }