Explorar o código

comment updates

Jonathan Turner %!s(int64=9) %!d(string=hai) anos
pai
achega
d986354f79
Modificáronse 2 ficheiros con 20 adicións e 26 borrados
  1. 15 22
      crypto/engine/engine.go
  2. 5 4
      crypto/engine/nfold.go

+ 15 - 22
crypto/engine/engine.go

@@ -9,17 +9,12 @@ import (
 	"github.com/jcmturner/gokrb5/crypto/etype"
 )
 
-// RFC3961: DR(Key, Constant) = k-truncate(E(Key, Constant, initial-cipher-state)).
-//
-// key - base key or protocol key. Likely to be a key from a keytab file.
-//
-// usage - a constant.
-//
-// n - block size in bits (not bytes) - note if you use something like aes.BlockSize this is in bytes.
-//
-// k - key length / key seed length in bits. Eg. for AES256 this value is 256.
-//
-// e - the encryption etype function to use.
+// RFC 3961: DR(Key, Constant) = k-truncate(E(Key, Constant, initial-cipher-state)).
+// key: base key or protocol key. Likely to be a key from a keytab file.
+// usage: a constant.
+// n: block size in bits (not bytes) - note if you use something like aes.BlockSize this is in bytes.
+// k: key length / key seed length in bits. Eg. for AES256 this value is 256.
+// e: the encryption etype function to use.
 func DeriveRandom(key, usage []byte, n, k int, e etype.EType) ([]byte, error) {
 	//Ensure the usage constant is at least the size of the cypher block size. Pass it through the nfold algorithm that will "stretch" it if needs be.
 	nFoldUsage := Nfold(usage, n)
@@ -149,25 +144,23 @@ func VerifyChecksum(key, chksum, msg []byte, usage uint32, etype etype.EType) bo
 	return hmac.Equal(chksum, expectedMAC)
 }
 
-/*
-Key Usage Numbers
-RFC 3961: The "well-known constant" used for the DK function is the key usage number, expressed as four octets in big-endian order, followed by one octet indicated below.
-Kc = DK(base-key, usage | 0x99);
-Ke = DK(base-key, usage | 0xAA);
-Ki = DK(base-key, usage | 0x55);
-*/
-
-// Get the checksum usage value for the usage number un
+// Get the checksum key usage value for the usage number un.
+// RFC 3961: The "well-known constant" used for the DK function is the key usage number, expressed as four octets in big-endian order, followed by one octet indicated below.
+// Kc = DK(base-key, usage | 0x99);
 func GetUsageKc(un uint32) []byte {
 	return getUsage(un, 0x99)
 }
 
-// Get the encryption usage value for the usage number un
+// Get the encryption key usage value for the usage number un
+// RFC 3961: The "well-known constant" used for the DK function is the key usage number, expressed as four octets in big-endian order, followed by one octet indicated below.
+// Ke = DK(base-key, usage | 0xAA);
 func GetUsageKe(un uint32) []byte {
 	return getUsage(un, 0xAA)
 }
 
-// Get the integrity usage value for the usage number un
+// Get the integrity key usage value for the usage number un
+// RFC 3961: The "well-known constant" used for the DK function is the key usage number, expressed as four octets in big-endian order, followed by one octet indicated below.
+// Ki = DK(base-key, usage | 0x55);
 func GetUsageKi(un uint32) []byte {
 	return getUsage(un, 0x55)
 }

+ 5 - 4
crypto/engine/nfold.go

@@ -34,9 +34,10 @@ https://svn.apache.org/repos/asf/directory/apacheds/tags/1.5.1/kerberos-shared/s
 License: http://www.apache.org/licenses/LICENSE-2.0
 */
 
-// n is in bits not bytes
-func Nfold(in []byte, n int) []byte {
-	k := len(in) * 8
+// RFC 3961: n-fold algorithm.
+// m input bytes that will be "stretched" to the least common multiple of n bits and the bit length of m.
+func Nfold(m []byte, n int) []byte {
+	k := len(m) * 8
 
 	//Get the lowest common multiple of the two bit sizes
 	lcm := lcm(n, k)
@@ -45,7 +46,7 @@ func Nfold(in []byte, n int) []byte {
 
 	for i := 0; i < relicate; i++ {
 		rotation := 13 * i
-		sumBytes = append(sumBytes, rotateRight(in, rotation)...)
+		sumBytes = append(sumBytes, rotateRight(m, rotation)...)
 	}
 
 	nfold := make([]byte, n/8)