-
Notifications
You must be signed in to change notification settings - Fork 14
Inconsistent signature length on ECDSA #68
Description
Hey,
I am building an hybrid application that shares the same code on both server and client sides. Same JS files, same modules. After some hours trying to figure out why I couldn't use WebCrypto -> Export ECDSA -> Send to the server -> Check the signature, I discovered that the signature has an inconsistent byte length and aways start with the very same bytes. This is the buf2hex read of it:
I found this pretty weird and almost sure that this should not happen. I run the same code on the browser to check if this behavior is normal. Here the results:
As I said before, this is the same code running. You can notice the difference. The code is the following. The "octano" module is just the layer to make the code runs on the browser and server. It keeps the same parameters as the original functions.
function test(){
var publicKeyExported = {
"crv": "P-256",
"ext": true,
"key_ops": [
"verify"
],
"kty": "EC",
"x": "oVlNnOyWWwcIfhd73uMLrldbAy2YMRtuTjIY1Xz-I1o",
"y": "RLMChUc4EOuWcjJcFr2knwxVsIiaTtLPsNRMFLK0ku4"
}
var privateKeyExported = {
"crv": "P-256",
"d": "VNLMIqrU9iBgPZIkxVrtIsB4wL6-lRE0e0SRNm0LeVY",
"ext": true,
"key_ops": [
"sign"
],
"kty": "EC",
"x": "oVlNnOyWWwcIfhd73uMLrldbAy2YMRtuTjIY1Xz-I1o",
"y": "RLMChUc4EOuWcjJcFr2knwxVsIiaTtLPsNRMFLK0ku4"
}
var algoDefine = {
"name": "ECDSA",
"namedCurve": "P-256"
}
var signAlgo = {name: "ECDSA", hash: {name: "SHA-256"}}
var dataToSign = 'test'
return Promise.all([
octano.util.importKey("jwk", privateKeyExported, algoDefine , true , ['sign']),
octano.util.importKey("jwk", publicKeyExported, algoDefine , true , ['verify'])
])
.then(x => {
return octano.util.signData(signAlgo, x[0], octano.util.textEncoder(dataToSign))
.then(x=>{return octano.util.buf2hex(x)})
})
.catch(e => {console.log(e)})
}
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
test().then(x => { console.log(x)}).catch(e => {console.log(e)})
INB4: Not the font, I use monospace.
IINB4: Not a problem on the buf2hex, I've tested it in another projects.