In this exercise we shall sign and verify messages using the ECDSA digital signature algorithm and the NIST P-521 curve. The NIST P-521 elliptic curve, known also as secp521r1 is 521-bit ECC curve, suitable for ECDSA digital signatures and ECDH key agreement. It uses 521-bit private keys (encoded as 65-66 bytes, 130-132 hex digits) and 1042-bit public keys (uncompressed, encoded as 130-131 bytes, 260-261 hex digits). The produced signature is 132 bytes (264 hex digits).

Sign a Message with ECDSA / P-521

Write a program to sign a message by given private key. The input consists of 2 text lines: message and private key. The message is given as text and the private key is given as hex string (130-132 hex digits). Use the ECDSA deterministic signing (following RFC 6979) and the curve NIST P-521, which also known as secp521r1. Print the output as JSON document, holding the input message + the public key of the signer (as hex string, uncompressed) + the ECDSA digital signature (as hex string).

Verify Message Signature with ECDSA / P-521

Write a program to validate the ECDSA digital signature, created by the previous exercise. The input comes as JSON document, holding the message + the public key (uncompressed, hex string) + the signature. Use the P-521 elliptic curve (secp521r1). Print as output a single word: "valid' or "invalid".