<PackageReference Include="BouncyCastle.Cryptography" Version="2.5.0" />

Poly1305KeyGenerator

Generates keys for the Poly1305 MAC.

public static void CheckKey(byte[] key)

Checks a 32 byte key for compliance with the Poly1305 key requirements, e.g. k[0] ... k[15], r[0] ... r[15] with the required bits in r cleared as per Clamp.

public static void Clamp(byte[] key)

Modifies an existing 32 byte key value to comply with the requirements of the Poly1305 key by clearing required bits in the r (second 16 bytes) portion of the key. Specifically: r[3], r[7], r[11], r[15] have top four bits clear (i.e., are {0, 1, . . . , 15})r[4], r[8], r[12] have bottom two bits clear (i.e., are in {0, 4, 8, . . . , 252})