template class xf::security::sm2¶
#include "sm234.hpp"
Overview¶
SM2 algorithm related function. This class provide signing and verifying functions.
Parameters:
| W | Bit width of SM2 curve’s parameters. |
template <int W> class sm2: public xf::security::ecc // fields ap_uint <W> Gx ap_uint <W> Gy ap_uint <W> n
Fields¶
ap_uint <W> Gx
X coordinate of generation point.
ap_uint <W> Gy
Y coordinate of generation point.
ap_uint <W> n
Order of generation point.
Methods¶
init¶
void init ( ap_uint <W> inputA, ap_uint <W> inputB, ap_uint <W> inputP, ap_uint <W> inputGx, ap_uint <W> inputGy, ap_uint <W> inputN )
Setup parameters for curve y^2 = x^3 + ax + b in GF(p)
Parameters:
| inputA | Parameter a for y^2 = x^3 + ax + b in GF(p) |
| inputB | Parameter b for y^2 = x^3 + ax + b in GF(p) |
| inputP | Parameter p for y^2 = x^3 + ax + b in GF(p) |
| inputGx | X coordinate of generation point G. |
| inputGy | Y coordinate of generation point G. |
| inputN | Order of generation point. |
sign¶
bool sign ( ap_uint <W> hashZaM, ap_uint <W> k, ap_uint <W> privateKey, ap_uint <W>& r, ap_uint <256>& s )
signing function. It will return true if input parameters are legal, otherwise return false.
Parameters:
| hashZaM | Digest value of message to be signed. |
| k | A random key to sign the message, should kept different each time to be used. |
| privateKey | Private Key to sign the message |
| r | part of signing pair {r, s} |
| s | part of signing pair {r, s} |
verify¶
bool verify ( ap_uint <W> r, ap_uint <W> s, ap_uint <W> hashZaM, ap_uint <W> Px, ap_uint <W> Py )
verifying function. It will return true if verified, otherwise false.
Parameters:
| r | part of signing pair {r, s} |
| s | part of signing pair {r, s} |
| hashZaM | Digest value of message to be signed. |
| Px | X coordinate of public key point P. |
| Py | Y coordinate of public key point P. |