#' Perform simple statistical calcuations
#' @description internal functions specific to the signing of transcations, including Edwards Double and Edwards Add.
#' @return bigz (big integer)
#' @references Some reference for the ed25519 algorithm: http://ed25519.cr.yp.to/
#' @note These functions were adapted from this gist by Johan Stén: https://gist.github.com/johansten/3859fb4f9a24a5b6fee5bef86a3ad91c
.inv <- function(x) {
return(powm(x, global$q - 2, global$q))
}
.square <- function(x) {
return (mul.bigz(x, x) %% global$q)
}
.mult <- function(x, y) {
return(mul.bigz(x, y) %% global$q)
}
.add <- function(x, y) {
return (add.bigz(x, y) %% global$q)
}
.edwards_add_b <- function(x, y, z) {
B = .square(z)
C = .mult(x, global$bx)
D = .mult(y, global$by)
E = .mult(global$d, .mult(C, D))
Fa = .add(B,-E)
G = .add(B, E)
H = .add(C, D)
x3 = .mult(z, .mult(Fa, .add(.mult(
.add(x, y), .add(global$bx, global$by)
),-H)))
y3 = .mult(z, .mult(G, H))
z3 = .mult(Fa, G)
return(c(x3, y3, z3))
}
.edwards_double <- function(x, y, z) {
sum2 = .square(.add(x, y))
x2 = .square(x)
y2 = .square(y)
z2 = .square(z)
e = .add(x2, y2)
Fa = .add(x2,-y2)
j = .add(.add(z2, z2), Fa)
x3 = .mult(.add(e,-sum2), j)
y3 = .mult(Fa, e)
z3 = .mult(Fa, j)
return(c(x3, y3, z3))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.