Content-Length: 374900 | pFad | http://github.com/jruby/jruby-openssl/commit/6345910ebf326f5778f67c124287b45e30e829f5

82 Implement Point#mul · jruby/jruby-openssl@6345910 · GitHub
Skip to content

Commit 6345910

Browse files
committed
Implement Point#mul
1 parent aa1db88 commit 6345910

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src/main/java/org/jruby/ext/openssl/PKeyEC.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec;
5959
import org.bouncycastle.jce.spec.ECNamedCurveSpec;
6060

61+
import org.bouncycastle.math.ec.ECAlgorithms;
62+
import org.bouncycastle.math.ec.ECCurve;
6163
import org.jruby.Ruby;
6264
import org.jruby.RubyArray;
6365
import org.jruby.RubyBoolean;
@@ -972,6 +974,7 @@ private boolean getPointAndGroup(ThreadContext context, IRubyObject groupOrPoint
972974

973975
if ( groupOrPoint instanceof Group) {
974976
this.group = (Group) groupOrPoint;
977+
this.point = (ECPoint) ((Group) groupOrPoint).generator(context);
975978
} else {
976979
throw runtime.newTypeError(groupOrPoint, _EC(runtime).getClass("Group"));
977980
}
@@ -1068,6 +1071,53 @@ public IRubyObject inspect() {
10681071
return ObjectSupport.inspect(this, (List) Collections.singletonList(entry));
10691072
}
10701073

1074+
@JRubyMethod(name = "mul", required = 1, optional = 2)
1075+
public IRubyObject mul(final ThreadContext context, final IRubyObject[] args) {
1076+
Ruby runtime = context.runtime;
1077+
1078+
org.bouncycastle.math.ec.ECPoint pointSelf, pointResult;
1079+
1080+
Group groupV = this.group;
1081+
1082+
Point result;
1083+
1084+
BigInteger bn_g = null;
1085+
1086+
ECCurve selfCurve = EC5Util.convertCurve(group.getCurve());
1087+
pointSelf = EC5Util.convertPoint(selfCurve, asECPoint());
1088+
1089+
result = new Point(runtime, getMetaClass());
1090+
result.initialize(context, groupV);
1091+
ECCurve resultCurve = EC5Util.convertCurve(result.group.getCurve());
1092+
pointResult = EC5Util.convertPoint(resultCurve, result.point);
1093+
1094+
int argc = Arity.checkArgumentCount(runtime, args, 1, 3);
1095+
IRubyObject arg1 = args[0], arg2 = args[1], arg3 = args[2];
1096+
if (!(arg1 instanceof RubyArray)) {
1097+
BigInteger bn = ((BN) arg1).getValue();
1098+
1099+
if (!arg2.isNil()) {
1100+
bn_g = ((BN) arg2).getValue();
1101+
}
1102+
1103+
if (bn_g == null) {
1104+
org.bouncycastle.math.ec.ECPoint mulPoint = ECAlgorithms.referenceMultiply(pointSelf, bn);
1105+
result = new Point(runtime, EC5Util.convertPoint(mulPoint), result.group);
1106+
} else {
1107+
org.bouncycastle.math.ec.ECPoint mulPoint = ECAlgorithms.sumOfTwoMultiplies(pointResult, bn_g, pointSelf, bn);
1108+
result = new Point(runtime, EC5Util.convertPoint(mulPoint), result.group);
1109+
}
1110+
1111+
if (result == null) {
1112+
newECError(runtime, "bad multiply result");
1113+
}
1114+
} else {
1115+
throw runtime.newNotImplementedError("calling #mul with arrays is not supported by this OpenSSL version");
1116+
}
1117+
1118+
return result;
1119+
}
1120+
10711121
@Deprecated
10721122
public IRubyObject initialize(final ThreadContext context, final IRubyObject[] args) {
10731123
final int argc = Arity.checkArgumentCount(context.runtime, args, 1, 2);

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/jruby/jruby-openssl/commit/6345910ebf326f5778f67c124287b45e30e829f5

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy