]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
tests/krb5: Add methods to obtain the length of checksum types
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Wed, 1 Sep 2021 03:50:26 +0000 (15:50 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 13 Sep 2021 23:11:35 +0000 (23:11 +0000)
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Isaac Boukris <iboukris@samba.org>
python/samba/tests/krb5/kcrypto.py

index ce7b00bda4c59ffe218d490a63f3aed90ad958c1..4a4a12a66d4df461f79db6658964ac5a7a3db366 100755 (executable)
@@ -478,6 +478,7 @@ class _ChecksumProfile(object):
     # define:
     #   * checksum
     #   * verify (if verification is not just checksum-and-compare)
+    #   * checksum_len
     @classmethod
     def verify(cls, key, keyusage, text, cksum):
         expected = cls.checksum(key, keyusage, text)
@@ -504,6 +505,10 @@ class _SimplifiedChecksum(_ChecksumProfile):
             raise ValueError('Wrong key type for checksum')
         super(_SimplifiedChecksum, cls).verify(key, keyusage, text, cksum)
 
+    @classmethod
+    def checksum_len(cls):
+        return cls.macsize
+
 
 class _SHA1AES128(_SimplifiedChecksum):
     macsize = 12
@@ -533,6 +538,10 @@ class _HMACMD5(_ChecksumProfile):
             raise ValueError('Wrong key type for checksum')
         super(_HMACMD5, cls).verify(key, keyusage, text, cksum)
 
+    @classmethod
+    def checksum_len(cls):
+        return hashes.MD5.digest_size
+
 
 class _MD5(_ChecksumProfile):
     @classmethod
@@ -540,6 +549,10 @@ class _MD5(_ChecksumProfile):
         # This is unkeyed!
         return SIMPLE_HASH(text, hashes.MD5)
 
+    @classmethod
+    def checksum_len(cls):
+        return hashes.MD5.digest_size
+
 
 class _SHA1(_ChecksumProfile):
     @classmethod
@@ -547,6 +560,10 @@ class _SHA1(_ChecksumProfile):
         # This is unkeyed!
         return SIMPLE_HASH(text, hashes.SHA1)
 
+    @classmethod
+    def checksum_len(cls):
+        return hashes.SHA1.digest_size
+
 
 class _CRC32(_ChecksumProfile):
     @classmethod
@@ -555,6 +572,10 @@ class _CRC32(_ChecksumProfile):
         cksum = (~crc32(text, 0xffffffff)) & 0xffffffff
         return pack('<I', cksum)
 
+    @classmethod
+    def checksum_len(cls):
+        return 4
+
 
 _enctype_table = {
     Enctype.DES3: _DES3CBC,
@@ -643,6 +664,11 @@ def verify_checksum(cksumtype, key, keyusage, text, cksum):
     c.verify(key, keyusage, text, cksum)
 
 
+def checksum_len(cksumtype):
+    c = _get_checksum_profile(cksumtype)
+    return c.checksum_len()
+
+
 def prfplus(key, pepper, ln):
     # Produce ln bytes of output using the RFC 6113 PRF+ function.
     out = b''