# Secp256k1 test examples

Are there any available test cases for testing elliptic curves like secp256k1 (Korblitz curves from http://www.secg.org/collateral/sec2_final.pdf)? For curves like P192 there are for example those values: http://point-at-infinity.org/ecc/nisttv .

Moreover, what other ways one should test an implementation of an elliptic curve to make sure it is working correctly in all the scenarios used in encryption software?

Are there any easy to understand examples/tutorials of how to program and test elliptic curve algorithms that are available online?

-

Here are five test vectors for secp256k1, which I just generated with my own code. My code is a generic implementation of elliptic curves; it has been tested for many curves for which test vectors were available (in particular the NIST curves) so I tend to believe that it is correct. Each test vector is a value $m$ (chosen randomly modulo the curve order $n$) and the coordinates $(X, Y)$ of the point $mG$, where $G$ is the conventional generator defined in section 2.7.1 of SEC 2.

m = AA5E28D6A97A2479A65527F7290311A3624D4CC0FA1578598EE3C2613BF99522
Y = 0B71EA9BD730FD8923F6D25A7A91E7DD7728A960686CB5A901BB419E0F2CA232

X = D74BF844B0862475103D96A611CF2D898447E288D34B360BC885CB8CE7C00575
Y = 131C670D414C4546B88AC3FF664611B1C38CEB1C21D76369D7A7A0969D61D97D

m = 6461E6DF0FE7DFD05329F41BF771B86578143D4DD1F7866FB4CA7E97C5FA945D
X = E8AECC370AEDD953483719A116711963CE201AC3EB21D3F3257BB48668C6A72F
Y = C25CAF2F0EBA1DDB2F0F3F47866299EF907867B7D27E95B3873BF98397B24EE1

X = 14890E61FCD4B0BD92E5B36C81372CA6FED471EF3AA60A3E415EE4FE987DABA1

m = 1B22644A7BE026548810C378D0B2994EEFA6D2B9881803CB02CEFF865287D1B9
Y = F449A8376906482A84ED01479BD18882B919C140D638307F0C0934BA12590BDE


For self-testing an elliptic curve implementation, I suggest first verifying that multiplying $G$ by $n$ (the expected curve order) indeed yields the point at infinity. Then, do the following many times:

• Choose two random integers modulo $n$; call them $a$ and $b$.
• Compute $c = a + b$.
• Compute points $P = aG$, $Q = bG$ and $R = cG$.
• Verify that $P + Q = Q + P = R$.

If you go through this a few dozen times with no errors then chances are that your implementation is at least mostly correct.

A must-have reference on elliptic curve implementation is the Guide to Elliptic Curve Cryptography. It is not free, but worth its price. Good university libraries will let you read it without spending a dime on it.

-