ceremonyclient/bedlam/pkg/math/modp.qcl
Cassandra Heart dbd95bd9e9
v2.1.0 (#439)
* 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
2025-09-30 02:48:15 -05:00

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)
}