Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
briar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julian Dehm
briar
Commits
14e1cd60
Commit
14e1cd60
authored
11 years ago
by
akwizgran
Browse files
Options
Downloads
Patches
Plain Diff
Normalise elliptic curve points.
parent
a168a7ba
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
briar-core/src/org/briarproject/crypto/Sec1KeyParser.java
+5
-3
5 additions, 3 deletions
briar-core/src/org/briarproject/crypto/Sec1KeyParser.java
briar-core/src/org/briarproject/crypto/Sec1PublicKey.java
+4
-3
4 additions, 3 deletions
briar-core/src/org/briarproject/crypto/Sec1PublicKey.java
with
9 additions
and
6 deletions
briar-core/src/org/briarproject/crypto/Sec1KeyParser.java
+
5
−
3
View file @
14e1cd60
...
...
@@ -9,6 +9,7 @@ import org.briarproject.api.crypto.PublicKey;
import
org.spongycastle.crypto.params.ECDomainParameters
;
import
org.spongycastle.crypto.params.ECPrivateKeyParameters
;
import
org.spongycastle.crypto.params.ECPublicKeyParameters
;
import
org.spongycastle.math.ec.ECCurve
;
import
org.spongycastle.math.ec.ECPoint
;
/**
...
...
@@ -50,13 +51,14 @@ class Sec1KeyParser implements KeyParser {
BigInteger
y
=
new
BigInteger
(
1
,
yBytes
);
// Positive signum
if
(
y
.
compareTo
(
modulus
)
>=
0
)
throw
new
GeneralSecurityException
();
// Verify that y^2 == x^3 + ax + b (mod p)
BigInteger
a
=
params
.
getCurve
().
getA
().
toBigInteger
();
BigInteger
b
=
params
.
getCurve
().
getB
().
toBigInteger
();
ECCurve
curve
=
params
.
getCurve
();
BigInteger
a
=
curve
.
getA
().
toBigInteger
();
BigInteger
b
=
curve
.
getB
().
toBigInteger
();
BigInteger
lhs
=
y
.
multiply
(
y
).
mod
(
modulus
);
BigInteger
rhs
=
x
.
multiply
(
x
).
add
(
a
).
multiply
(
x
).
add
(
b
).
mod
(
modulus
);
if
(!
lhs
.
equals
(
rhs
))
throw
new
GeneralSecurityException
();
// We know the point (x, y) is on the curve, so we can create the point
ECPoint
pub
=
params
.
getC
urve
()
.
createPoint
(
x
,
y
);
ECPoint
pub
=
c
urve
.
createPoint
(
x
,
y
)
.
normalize
()
;
// Verify that the point (x, y) is not the point at infinity
if
(
pub
.
isInfinity
())
throw
new
GeneralSecurityException
();
// Verify that the point (x, y) times n is the point at infinity
...
...
This diff is collapsed.
Click to expand it.
briar-core/src/org/briarproject/crypto/Sec1PublicKey.java
+
4
−
3
View file @
14e1cd60
package
org.briarproject.crypto
;
import
org.briarproject.api.crypto.PublicKey
;
import
org.spongycastle.crypto.params.ECPublicKeyParameters
;
import
org.spongycastle.math.ec.ECPoint
;
/**
* An elliptic curve public key that uses the encoding defined in "SEC 1:
...
...
@@ -23,9 +23,10 @@ class Sec1PublicKey implements PublicKey {
public
byte
[]
getEncoded
()
{
byte
[]
encodedKey
=
new
byte
[
publicKeyBytes
];
encodedKey
[
0
]
=
4
;
byte
[]
x
=
key
.
getQ
().
getAffineXCoord
().
toBigInteger
().
toByteArray
();
ECPoint
pub
=
key
.
getQ
().
normalize
();
byte
[]
x
=
pub
.
getAffineXCoord
().
toBigInteger
().
toByteArray
();
Sec1Utils
.
convertToFixedLength
(
x
,
encodedKey
,
1
,
bytesPerInt
);
byte
[]
y
=
key
.
getQ
()
.
getAffineYCoord
().
toBigInteger
().
toByteArray
();
byte
[]
y
=
pub
.
getAffineYCoord
().
toBigInteger
().
toByteArray
();
Sec1Utils
.
convertToFixedLength
(
y
,
encodedKey
,
1
+
bytesPerInt
,
bytesPerInt
);
return
encodedKey
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment