class xf::security::eddsaEd25519

#include "eddsa.hpp"

Overview

Edwards-curve Digital Signature Algorithm on curve ed25519. It take RFC 8032 “Edwards-Curve Digital Signature Algorithm (EdDSA)” as reference. This class provide signing and verifying functions.

// fields

const int b
const int c
const int n
const int a
const ap_uint <256> Bx
const ap_uint <256> By
const ap_uint <256> L
const ap_uint <256> p
const ap_uint <256> d
const ap_uint <256> p_5_d8
const ap_uint <256> sqrt_n1
const ap_uint <256> rMod
ap_uint <64> head[8]

Fields

const int b

ed25519 related curve parameters.

Methods

compress

void compress (
    ap_uint <256> x,
    ap_uint <256> y,
    ap_uint <256>& res
    )

Compress a point (x, y) on curve to its compressed form.

Parameters:

x X coordinate of point.
y Y coordinate of point.
res compressed point representation.

modularSqrt

bool modularSqrt (
    ap_uint <256> u,
    ap_uint <256> v,
    ap_uint <256>& sqrt_a
    )

Calculate square root of u/v.

Parameters:

u Input u of u/v to calculate square root.
v Input u of u/v to calculate square root.
sqrt_a Square root of u/v.

decompress

bool decompress (
    ap_uint <256> P,
    ap_uint <256>& Px,
    ap_uint <256>& Py
    )

Decompress a point (Px, Py) from its compressed representation.

Parameters:

P compressed point representation.
Px X coordinate of the point.
Py Y coordinate of the point.

pointAdd

void pointAdd (
    ap_uint <256> x1,
    ap_uint <256> y1,
    ap_uint <256> x2,
    ap_uint <256> y2,
    ap_uint <256>& x3,
    ap_uint <256>& y3
    )

perform point addition in ed25519, (x3, y3) = (x1, y1) + (x2, y2)

Parameters:

x1 X coordinate of point 1.
y1 Y coordinate of point 1.
x2 X coordinate of point 2.
y2 Y coordinate of point 2.
x3 X coordinate of point 3.
y3 Y coordinate of point 3.

pointMul

void pointMul (
    ap_uint <256> x,
    ap_uint <256> y,
    ap_uint <256> mag,
    ap_uint <256>& resX,
    ap_uint <256>& resY
    )

perform point multiply scalar in ed25519, (resX, resY) = (x, y) * mag

Parameters:

x X coordinate of point to be multiplied.
y Y coordinate of point to be multiplied.
mag scalar operand of this multiplication.
resX X coordinate of result.
resY Y coordinate of result.

generatePublicKey

void generatePublicKey (
    ap_uint <256> privateKey,
    ap_uint <256>& publicKey,
    ap_uint <512>& privateKeyHash
    )

Generate public key and digest value of privateKey hash value from privateKey.

Parameters:

privateKey Private Key.
publicKey Public Key.
privateKeyHash Digest value of private key.

sign

void sign (
    hls::stream <ap_uint <64>>& msgStrm,
    hls::stream <ap_uint <128>>& lenStrm,
    hls::stream <bool>& endLenStrm,
    ap_uint <256> publicKey,
    ap_uint <512> privateKeyHash,
    hls::stream <ap_uint <512>>& signatureStrm,
    hls::stream <bool>& endSignatureStrm
    )

signing function

Parameters:

msgStrm Stream to input messages to be signed, each message should be input throught this stream twice.
lenStrm Stream to input length of input messages.
endLenStrm Stream of end flag of lenStrm.
publicKey Public Key.
privateKeyHash Digest value of private key.
signatureStrm Stream to output signature.
endSignatureStrm Stream of end flag of signatureStrm.

verify

void verify (
    hls::stream <ap_uint <64>>& msgStrm,
    hls::stream <ap_uint <128>>& lenStrm,
    hls::stream <ap_uint <512>>& signatureStrm,
    hls::stream <bool>& endSignatureStrm,
    hls::stream <ap_uint <256>>& publicKeyStrm,
    hls::stream <bool>& ifValidStrm,
    hls::stream <bool>& endIfValidStrm
    )

verifying function

Parameters:

msgStrm Stream to input messages to be signed.
lenStrm Stream to input length of input messages.
signatureStrm Stream to input signatures.
endSignatureStrm Stream of end flag of signatures.
publicKeyStrm Stream to input public key.
ifValidStrm Stream to output if message signature is valid.
endIfValidStrm Stream of end flag of ifValidStrm.