Get X-Coordinate of Elliptical Curve using Bouncy Castle
I tried to calculate Tr(x) operation for x coordinate of the elliptical curve F2m (m = 163). For that, I used "Bouncy Castle" with corresponding types. Trace for my elliptical curve is equal to either 0 or 1 and my code is the following:
public int CalculateTrace_Test(byte array)
{
int m = 163;
BigInteger two = new BigInteger("2", 10);
BigInteger x = new BigInteger(array);
BigInteger xi = x;
BigInteger temp = x;
for (int i = 1; i < m; i++)
{
var next = xi.ModPow(two.Pow(i), fx);
temp = temp.Xor(next);
}
return temp.IntValue;
}
Here fx is an integer formed from the irreducible polynomial f(x) = x^163+x^7+x^6+x^3 + 1
.
So my problem that it doesn't work and as result, I have everything but not 1 or 0. Could anyone please tell me what is wrong in my implementation of the trace?
java cryptography bouncycastle
add a comment |
I tried to calculate Tr(x) operation for x coordinate of the elliptical curve F2m (m = 163). For that, I used "Bouncy Castle" with corresponding types. Trace for my elliptical curve is equal to either 0 or 1 and my code is the following:
public int CalculateTrace_Test(byte array)
{
int m = 163;
BigInteger two = new BigInteger("2", 10);
BigInteger x = new BigInteger(array);
BigInteger xi = x;
BigInteger temp = x;
for (int i = 1; i < m; i++)
{
var next = xi.ModPow(two.Pow(i), fx);
temp = temp.Xor(next);
}
return temp.IntValue;
}
Here fx is an integer formed from the irreducible polynomial f(x) = x^163+x^7+x^6+x^3 + 1
.
So my problem that it doesn't work and as result, I have everything but not 1 or 0. Could anyone please tell me what is wrong in my implementation of the trace?
java cryptography bouncycastle
add a comment |
I tried to calculate Tr(x) operation for x coordinate of the elliptical curve F2m (m = 163). For that, I used "Bouncy Castle" with corresponding types. Trace for my elliptical curve is equal to either 0 or 1 and my code is the following:
public int CalculateTrace_Test(byte array)
{
int m = 163;
BigInteger two = new BigInteger("2", 10);
BigInteger x = new BigInteger(array);
BigInteger xi = x;
BigInteger temp = x;
for (int i = 1; i < m; i++)
{
var next = xi.ModPow(two.Pow(i), fx);
temp = temp.Xor(next);
}
return temp.IntValue;
}
Here fx is an integer formed from the irreducible polynomial f(x) = x^163+x^7+x^6+x^3 + 1
.
So my problem that it doesn't work and as result, I have everything but not 1 or 0. Could anyone please tell me what is wrong in my implementation of the trace?
java cryptography bouncycastle
I tried to calculate Tr(x) operation for x coordinate of the elliptical curve F2m (m = 163). For that, I used "Bouncy Castle" with corresponding types. Trace for my elliptical curve is equal to either 0 or 1 and my code is the following:
public int CalculateTrace_Test(byte array)
{
int m = 163;
BigInteger two = new BigInteger("2", 10);
BigInteger x = new BigInteger(array);
BigInteger xi = x;
BigInteger temp = x;
for (int i = 1; i < m; i++)
{
var next = xi.ModPow(two.Pow(i), fx);
temp = temp.Xor(next);
}
return temp.IntValue;
}
Here fx is an integer formed from the irreducible polynomial f(x) = x^163+x^7+x^6+x^3 + 1
.
So my problem that it doesn't work and as result, I have everything but not 1 or 0. Could anyone please tell me what is wrong in my implementation of the trace?
java cryptography bouncycastle
java cryptography bouncycastle
edited Nov 27 '18 at 15:00
Lauren Van Sloun
1,02921018
1,02921018
asked Nov 27 '18 at 14:03
Rotvik KnuzichRotvik Knuzich
113
113
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
It doesn't look like you are properly doing field arithmetic in GF(2m). The classes that support correct field arithmetic are in the package org.bouncycastle.math.ec
. Take a look at ECFieldElement.F2m
and ECCurve.F2m
. Also, for your specific case which corresponds to the SECT163 reduction polynomial, the class SecT163FieldElement
may be particularly useful.
Here some code copied directly from the class org.bouncycastle.math.ec.tools.TraceOptimizer
. The code assumes the the finite field is of characteristic 2.
private static int calculateTrace(ECFieldElement fe) {
int m = fe.getFieldSize();
ECFieldElement tr = fe;
for (int i = 1; i < m; ++i) {
fe = fe.square();
tr = tr.add(fe);
}
BigInteger b = tr.toBigInteger();
if (b.bitLength() > 1) {
throw new IllegalStateException();
}
return b.intValue();
Sorry, but what is "characteristic 2" ? F2m ?
– Rotvik Knuzich
Nov 27 '18 at 17:55
No wikipedia for you? Read this.
– James K Polk
Nov 27 '18 at 20:16
Thank You, i adapted your code because in C# version "BouncyCastle" there are no such classes and now it does work. About "characteristic 2", in your code ECFieldElement is used, not F2mFieldElement in case of the binary fields
– Rotvik Knuzich
Nov 28 '18 at 9:10
1
There is no C# in the question nor answer, so I'm not sure what that comment is about.
– Maarten Bodewes
Dec 4 '18 at 14:31
@RotvikKnuzich: If you were interested in C# then why not mention that in your question?
– James K Polk
Dec 4 '18 at 19:40
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53501466%2fget-x-coordinate-of-elliptical-curve-using-bouncy-castle%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It doesn't look like you are properly doing field arithmetic in GF(2m). The classes that support correct field arithmetic are in the package org.bouncycastle.math.ec
. Take a look at ECFieldElement.F2m
and ECCurve.F2m
. Also, for your specific case which corresponds to the SECT163 reduction polynomial, the class SecT163FieldElement
may be particularly useful.
Here some code copied directly from the class org.bouncycastle.math.ec.tools.TraceOptimizer
. The code assumes the the finite field is of characteristic 2.
private static int calculateTrace(ECFieldElement fe) {
int m = fe.getFieldSize();
ECFieldElement tr = fe;
for (int i = 1; i < m; ++i) {
fe = fe.square();
tr = tr.add(fe);
}
BigInteger b = tr.toBigInteger();
if (b.bitLength() > 1) {
throw new IllegalStateException();
}
return b.intValue();
Sorry, but what is "characteristic 2" ? F2m ?
– Rotvik Knuzich
Nov 27 '18 at 17:55
No wikipedia for you? Read this.
– James K Polk
Nov 27 '18 at 20:16
Thank You, i adapted your code because in C# version "BouncyCastle" there are no such classes and now it does work. About "characteristic 2", in your code ECFieldElement is used, not F2mFieldElement in case of the binary fields
– Rotvik Knuzich
Nov 28 '18 at 9:10
1
There is no C# in the question nor answer, so I'm not sure what that comment is about.
– Maarten Bodewes
Dec 4 '18 at 14:31
@RotvikKnuzich: If you were interested in C# then why not mention that in your question?
– James K Polk
Dec 4 '18 at 19:40
add a comment |
It doesn't look like you are properly doing field arithmetic in GF(2m). The classes that support correct field arithmetic are in the package org.bouncycastle.math.ec
. Take a look at ECFieldElement.F2m
and ECCurve.F2m
. Also, for your specific case which corresponds to the SECT163 reduction polynomial, the class SecT163FieldElement
may be particularly useful.
Here some code copied directly from the class org.bouncycastle.math.ec.tools.TraceOptimizer
. The code assumes the the finite field is of characteristic 2.
private static int calculateTrace(ECFieldElement fe) {
int m = fe.getFieldSize();
ECFieldElement tr = fe;
for (int i = 1; i < m; ++i) {
fe = fe.square();
tr = tr.add(fe);
}
BigInteger b = tr.toBigInteger();
if (b.bitLength() > 1) {
throw new IllegalStateException();
}
return b.intValue();
Sorry, but what is "characteristic 2" ? F2m ?
– Rotvik Knuzich
Nov 27 '18 at 17:55
No wikipedia for you? Read this.
– James K Polk
Nov 27 '18 at 20:16
Thank You, i adapted your code because in C# version "BouncyCastle" there are no such classes and now it does work. About "characteristic 2", in your code ECFieldElement is used, not F2mFieldElement in case of the binary fields
– Rotvik Knuzich
Nov 28 '18 at 9:10
1
There is no C# in the question nor answer, so I'm not sure what that comment is about.
– Maarten Bodewes
Dec 4 '18 at 14:31
@RotvikKnuzich: If you were interested in C# then why not mention that in your question?
– James K Polk
Dec 4 '18 at 19:40
add a comment |
It doesn't look like you are properly doing field arithmetic in GF(2m). The classes that support correct field arithmetic are in the package org.bouncycastle.math.ec
. Take a look at ECFieldElement.F2m
and ECCurve.F2m
. Also, for your specific case which corresponds to the SECT163 reduction polynomial, the class SecT163FieldElement
may be particularly useful.
Here some code copied directly from the class org.bouncycastle.math.ec.tools.TraceOptimizer
. The code assumes the the finite field is of characteristic 2.
private static int calculateTrace(ECFieldElement fe) {
int m = fe.getFieldSize();
ECFieldElement tr = fe;
for (int i = 1; i < m; ++i) {
fe = fe.square();
tr = tr.add(fe);
}
BigInteger b = tr.toBigInteger();
if (b.bitLength() > 1) {
throw new IllegalStateException();
}
return b.intValue();
It doesn't look like you are properly doing field arithmetic in GF(2m). The classes that support correct field arithmetic are in the package org.bouncycastle.math.ec
. Take a look at ECFieldElement.F2m
and ECCurve.F2m
. Also, for your specific case which corresponds to the SECT163 reduction polynomial, the class SecT163FieldElement
may be particularly useful.
Here some code copied directly from the class org.bouncycastle.math.ec.tools.TraceOptimizer
. The code assumes the the finite field is of characteristic 2.
private static int calculateTrace(ECFieldElement fe) {
int m = fe.getFieldSize();
ECFieldElement tr = fe;
for (int i = 1; i < m; ++i) {
fe = fe.square();
tr = tr.add(fe);
}
BigInteger b = tr.toBigInteger();
if (b.bitLength() > 1) {
throw new IllegalStateException();
}
return b.intValue();
edited Nov 27 '18 at 17:14
answered Nov 27 '18 at 16:25
James K PolkJames K Polk
30.3k116896
30.3k116896
Sorry, but what is "characteristic 2" ? F2m ?
– Rotvik Knuzich
Nov 27 '18 at 17:55
No wikipedia for you? Read this.
– James K Polk
Nov 27 '18 at 20:16
Thank You, i adapted your code because in C# version "BouncyCastle" there are no such classes and now it does work. About "characteristic 2", in your code ECFieldElement is used, not F2mFieldElement in case of the binary fields
– Rotvik Knuzich
Nov 28 '18 at 9:10
1
There is no C# in the question nor answer, so I'm not sure what that comment is about.
– Maarten Bodewes
Dec 4 '18 at 14:31
@RotvikKnuzich: If you were interested in C# then why not mention that in your question?
– James K Polk
Dec 4 '18 at 19:40
add a comment |
Sorry, but what is "characteristic 2" ? F2m ?
– Rotvik Knuzich
Nov 27 '18 at 17:55
No wikipedia for you? Read this.
– James K Polk
Nov 27 '18 at 20:16
Thank You, i adapted your code because in C# version "BouncyCastle" there are no such classes and now it does work. About "characteristic 2", in your code ECFieldElement is used, not F2mFieldElement in case of the binary fields
– Rotvik Knuzich
Nov 28 '18 at 9:10
1
There is no C# in the question nor answer, so I'm not sure what that comment is about.
– Maarten Bodewes
Dec 4 '18 at 14:31
@RotvikKnuzich: If you were interested in C# then why not mention that in your question?
– James K Polk
Dec 4 '18 at 19:40
Sorry, but what is "characteristic 2" ? F2m ?
– Rotvik Knuzich
Nov 27 '18 at 17:55
Sorry, but what is "characteristic 2" ? F2m ?
– Rotvik Knuzich
Nov 27 '18 at 17:55
No wikipedia for you? Read this.
– James K Polk
Nov 27 '18 at 20:16
No wikipedia for you? Read this.
– James K Polk
Nov 27 '18 at 20:16
Thank You, i adapted your code because in C# version "BouncyCastle" there are no such classes and now it does work. About "characteristic 2", in your code ECFieldElement is used, not F2mFieldElement in case of the binary fields
– Rotvik Knuzich
Nov 28 '18 at 9:10
Thank You, i adapted your code because in C# version "BouncyCastle" there are no such classes and now it does work. About "characteristic 2", in your code ECFieldElement is used, not F2mFieldElement in case of the binary fields
– Rotvik Knuzich
Nov 28 '18 at 9:10
1
1
There is no C# in the question nor answer, so I'm not sure what that comment is about.
– Maarten Bodewes
Dec 4 '18 at 14:31
There is no C# in the question nor answer, so I'm not sure what that comment is about.
– Maarten Bodewes
Dec 4 '18 at 14:31
@RotvikKnuzich: If you were interested in C# then why not mention that in your question?
– James K Polk
Dec 4 '18 at 19:40
@RotvikKnuzich: If you were interested in C# then why not mention that in your question?
– James K Polk
Dec 4 '18 at 19:40
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53501466%2fget-x-coordinate-of-elliptical-curve-using-bouncy-castle%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown