mirror of
https://github.com/QuilibriumNetwork/ceremonyclient.git
synced 2026-02-21 10:27:26 +08:00
* v2.1.0 [omit consensus and adjacent] - this commit will be amended with the full release after the file copy is complete * 2.1.0 main node rollup
27 lines
438 B
Go
27 lines
438 B
Go
// -*- go -*-
|
|
//
|
|
// Copyright (c) 2020 Markku Rossi
|
|
//
|
|
// All rights reserved.
|
|
//
|
|
|
|
package math
|
|
|
|
// Exp computes modular exponentiation b**e mod |m| (i.e. the sign of
|
|
// m is ignore).
|
|
func Exp(b, e, m uint) uint {
|
|
rType := make(uint, size(m))
|
|
mType := make(uint, size(m)*2)
|
|
|
|
var r mType = 1
|
|
|
|
for i := size(e) - 1; i >= 0; i = i - 1 {
|
|
r = r * r % mType(m)
|
|
if e>>i&1 != 0 {
|
|
r = r * mType(b) % mType(m)
|
|
}
|
|
}
|
|
|
|
return rType(r)
|
|
}
|