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

Function octetstring2key

scapy/libs/rfc3961.py:1454–1479  ·  view source on GitHub ↗

RFC4556 octetstring2key:: octetstring2key(x) == random-to-key(K-truncate( SHA1(0x00 | x) | SHA1(0x01 | x) | SHA1(0x02 | x) | ... ))

(etype: EncryptionType, x: bytes)

Source from the content-addressed store, hash-verified

1452############
1453
1454def octetstring2key(etype: EncryptionType, x: bytes) -> Key:
1455 """
1456 RFC4556 octetstring2key::
1457
1458 octetstring2key(x) == random-to-key(K-truncate(
1459 SHA1(0x00 | x) |
1460 SHA1(0x01 | x) |
1461 SHA1(0x02 | x) |
1462 ...
1463 ))
1464 """
1465 try:
1466 ep = _enctypes[etype]
1467 except ValueError:
1468 raise ValueError("Unknown etype '%s'" % etype)
1469
1470 out = b""
1471 count = 0
1472 while len(out) < ep.keysize:
1473 out += Hash_SHA().digest(struct.pack("!B", count) + x)
1474 count += 1
1475
1476 return Key.random_to_key(
1477 etype=etype,
1478 seed=out[:ep.keysize],
1479 )

Callers 1

Calls 3

Hash_SHAClass · 0.90
digestMethod · 0.45
random_to_keyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…