How to use Crypto++ for ECIES and retrieve common secret, authentication tag and ciphertext

326 views Asked by At

I'm trying to use the example in the crypto++ wiki for ecies encryption, which complies to IEEE P1363's version of the scheme. The first two steps of the scheme as described in ETSΙ ΤS 102 941 v1.3.1 standard are:

  1. Sender generates an ephemeral private key r in [1, q-1], ...

  2. Sender derives a shared secret S from receiver encryption public key Kr. S = Px, where ...

However, in the crypto++ example the first lines are:

    ECIES<ECP>::Decryptor d0(prng, ASN1::secp256r1());
    PrintPrivateKey(d0.GetKey());

    ECIES<ECP>::Encryptor e0(d0);
    PrintPublicKey(e0.GetKey());

which use a private for the decryptor and base the encryptor on it. I don't see how it matches the steps of the algorithm.

Moreover, the wiki states that the encryption function returns a tuple {K,C,T}, where K is the encrypted common secret, C is the ciphertext, and T is the authentication tag. But, in the example they are not retrieved and I don't see how they could.

Any insights and help would be greatly appreciated. Thank you!

1

There are 1 answers

1
he shouyong On

The output of the encryption function is the tuple {K,C,T}, where K is the encrypted common secret, C is the ciphertext, and T is the authentication tag.

K length is 64. T length is 32. C length is plaintext length.

if output string em0 is K+C+T (Fake code)

em0.length()-message.length() = 97
97+C_len = 04(fixed) + 64(K_len) + C(C_len) + 32( T_len).

Just parse the data according to the above instructions.