Skip to content

Commit d4b473d

Browse files
committedJun 10, 2022
8287178: IntegerModuloP::multiplicativeInverse returns 0 for 0
Reviewed-by: jnimeh
1 parent da2339c commit d4b473d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed
 

‎src/java.base/share/classes/sun/security/util/math/IntegerModuloP.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -156,6 +156,13 @@ default byte[] asByteArray(int len) {
156156
* @return the multiplicative inverse (1 / this)
157157
*/
158158
default ImmutableIntegerModuloP multiplicativeInverse() {
159+
// This method is used in 2 cases:
160+
// 1. To calculate the inverse of a number in ECDSAOperations,
161+
// this number must be non zero (modulo p).
162+
// 2. To flatten a 3D point to a 2D AffinePoint. This number
163+
// might be zero (infinity). However, since the infinity
164+
// is represented as (0, 0) in 2D, it’s OK returning 0 as
165+
// the inverse of 0, i.e. (1, 1, 0) == (1/0, 1/0) == (0, 0).
159166
return pow(getField().getSize().subtract(BigInteger.valueOf(2)));
160167
}
161168

0 commit comments

Comments
 (0)
Please sign in to comment.