RFC4556 octetstring2key:: octetstring2key(x) == random-to-key(K-truncate( SHA1(0x00 | x) | SHA1(0x01 | x) | SHA1(0x02 | x) | ... ))
(etype: EncryptionType, x: bytes)
| 1452 | ############ |
| 1453 | |
| 1454 | def 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 | ) |
no test coverage detected
searching dependent graphs…