(data, args)
| 14 | return sha.digest() |
| 15 | |
| 16 | def process(data, args): |
| 17 | # Generate ECC private key A |
| 18 | priv_a = ec.generate_private_key(ec.SECP256R1()) |
| 19 | |
| 20 | # Generate random ECC private key B |
| 21 | priv_b = ec.generate_private_key(ec.SECP256R1()) |
| 22 | pub_b = priv_b.public_key() |
| 23 | |
| 24 | # Perform ECDH: shared_secret = priv_a.exchange(ec.ECDH(), pub_b) |
| 25 | shared_secret = priv_a.exchange(ec.ECDH(), pub_b) |
| 26 | |
| 27 | # Derive AES key using HKDF |
| 28 | hkdf = HKDF( |
| 29 | algorithm=hashes.SHA256(), |
| 30 | length=32, |
| 31 | salt=None, |
| 32 | info=b'', |
| 33 | ) |
| 34 | aes_key = hkdf.derive(shared_secret) |
| 35 | |
| 36 | # Generate nonce |
| 37 | nonce = os.urandom(12) # AES-GCM uses 12-byte nonce |
| 38 | |
| 39 | # Encrypt data |
| 40 | aesgcm = AESGCM(aes_key) |
| 41 | ciphertext = aesgcm.encrypt(nonce, data, None) |
| 42 | |
| 43 | # Serialize keys |
| 44 | priv_a_bytes = priv_a.private_numbers().private_value.to_bytes(32, 'big') |
| 45 | pub_b_bytes = pub_b.public_bytes( |
| 46 | encoding=serialization.Encoding.X962, |
| 47 | format=serialization.PublicFormat.CompressedPoint |
| 48 | ) # 33 bytes: 0x02/0x03 + x |
| 49 | |
| 50 | # Final output: priv_a (32) + pub_b (33) + nonce (12) + ciphertext |
| 51 | final = priv_a_bytes + pub_b_bytes + nonce + ciphertext |
| 52 | return final |
nothing calls this directly
no outgoing calls
no test coverage detected