MCPcopy Create free account
hub / github.com/secdev/scapy / derive

Method derive

scapy/libs/rfc3961.py:498–515  ·  view source on GitHub ↗

Also known as "DK" in RFC3961.

(cls, key, constant)

Source from the content-addressed store, hash-verified

496
497 @classmethod
498 def derive(cls, key, constant):
499 # type: (Key, bytes) -> bytes
500 """
501 Also known as "DK" in RFC3961.
502 """
503 # RFC 3961 only says to n-fold the constant only if it is
504 # shorter than the cipher block size. But all Unix
505 # implementations n-fold constants if their length is larger
506 # than the block size as well, and n-folding when the length
507 # is equal to the block size is a no-op.
508 plaintext = _n_fold(constant, cls.blocksize)
509 rndseed = b""
510 while len(rndseed) < cls.seedsize:
511 ciphertext = cls.basic_encrypt(key.key, plaintext)
512 rndseed += ciphertext
513 plaintext = ciphertext
514 # DK(Key, Constant) = random-to-key(DR(Key, Constant))
515 return cls.random_to_key(rndseed[0 : cls.seedsize]).key
516
517 @classmethod
518 def encrypt(cls, key, keyusage, plaintext, confounder, signtext=None):

Callers

nothing calls this directly

Calls 3

_n_foldFunction · 0.85
basic_encryptMethod · 0.45
random_to_keyMethod · 0.45

Tested by

no test coverage detected