Skip to content

Commit 40469eb

Browse files
author
John Bland
committed
fix rng typo and remove encrypt/decrypt from ecc
1 parent a591e02 commit 40469eb

File tree

6 files changed

+2
-129
lines changed

6 files changed

+2
-129
lines changed

addon/wolfcrypt/ecc.cpp

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -178,48 +178,6 @@ Napi::Number bind_wc_ecc_verify_hash(const Napi::CallbackInfo& info)
178178
return Napi::Number::New( env, res );
179179
}
180180

181-
Napi::Number bind_wc_ecc_encrypt(const Napi::CallbackInfo& info)
182-
{
183-
int ret;
184-
Napi::Env env = info.Env();
185-
ecc_key* private_key = (ecc_key*)( info[0].As<Napi::Uint8Array>().Data() );
186-
ecc_key* public_key = (ecc_key*)( info[1].As<Napi::Uint8Array>().Data() );
187-
uint8_t* msg = info[2].As<Napi::Uint8Array>().Data();
188-
unsigned int msg_len = info[3].As<Napi::Number>().Uint32Value();
189-
uint8_t* out = info[4].As<Napi::Uint8Array>().Data();
190-
unsigned int out_len = info[5].As<Napi::Number>().Uint32Value();
191-
192-
ret = wc_ecc_encrypt( private_key, public_key, msg, msg_len, out, &out_len, NULL );
193-
194-
if ( ret < 0 )
195-
{
196-
out_len = ret;
197-
}
198-
199-
return Napi::Number::New( env, (int)out_len );
200-
}
201-
202-
Napi::Number bind_wc_ecc_decrypt(const Napi::CallbackInfo& info)
203-
{
204-
int ret;
205-
Napi::Env env = info.Env();
206-
ecc_key* private_key = (ecc_key*)( info[0].As<Napi::Uint8Array>().Data() );
207-
ecc_key* public_key = (ecc_key*)( info[1].As<Napi::Uint8Array>().Data() );
208-
uint8_t* msg = info[2].As<Napi::Uint8Array>().Data();
209-
unsigned int msg_len = info[3].As<Napi::Number>().Uint32Value();
210-
uint8_t* out = info[4].As<Napi::Uint8Array>().Data();
211-
unsigned int out_len = info[5].As<Napi::Number>().Uint32Value();
212-
213-
ret = wc_ecc_decrypt( private_key, public_key, msg, msg_len, out, &out_len, NULL );
214-
215-
if ( ret < 0 )
216-
{
217-
out_len = ret;
218-
}
219-
220-
return Napi::Number::New( env, (int)out_len );
221-
}
222-
223181
Napi::Number bind_wc_ecc_free(const Napi::CallbackInfo& info)
224182
{
225183
Napi::Env env = info.Env();

addon/wolfcrypt/h/ecc.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,4 @@ Napi::Number bind_wc_ecc_shared_secret(const Napi::CallbackInfo& info);
3434
Napi::Number bind_wc_ecc_sig_size(const Napi::CallbackInfo& info);
3535
Napi::Number bind_wc_ecc_sign_hash(const Napi::CallbackInfo& info);
3636
Napi::Number bind_wc_ecc_verify_hash(const Napi::CallbackInfo& info);
37-
Napi::Number bind_wc_ecc_encrypt(const Napi::CallbackInfo& info);
38-
Napi::Number bind_wc_ecc_decrypt(const Napi::CallbackInfo& info);
3937
Napi::Number bind_wc_ecc_free(const Napi::CallbackInfo& info);

addon/wolfcrypt/main.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ Napi::Object Init(Napi::Env env, Napi::Object exports)
104104
exports.Set(Napi::String::New(env, "wc_ecc_sig_size"), Napi::Function::New(env, bind_wc_ecc_sig_size));
105105
exports.Set(Napi::String::New(env, "wc_ecc_sign_hash"), Napi::Function::New(env, bind_wc_ecc_sign_hash));
106106
exports.Set(Napi::String::New(env, "wc_ecc_verify_hash"), Napi::Function::New(env, bind_wc_ecc_verify_hash));
107-
exports.Set(Napi::String::New(env, "wc_ecc_encrypt"), Napi::Function::New(env, bind_wc_ecc_encrypt));
108-
exports.Set(Napi::String::New(env, "wc_ecc_decrypt"), Napi::Function::New(env, bind_wc_ecc_decrypt));
109107
exports.Set(Napi::String::New(env, "wc_ecc_free"), Napi::Function::New(env, bind_wc_ecc_free));
110108

111109
return exports;

addon/wolfcrypt/rsa.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ Napi::Number bind_wc_FreeRsaKey(const Napi::CallbackInfo& info)
141141
Napi::Env env = info.Env();
142142
RsaKey* rsa = (RsaKey*)( info[0].As<Napi::Uint8Array>().Data() );
143143

144-
if ( ecc->rng != NULL )
144+
if ( rsa->rng != NULL )
145145
{
146-
wc_rng_free( ecc->rng );
146+
wc_rng_free( rsa->rng );
147147
}
148148

149149
ret = wc_FreeRsaKey( rsa );

interfaces/ecc.js

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -192,62 +192,6 @@ class WolfSSLEcc
192192
return false
193193
}
194194

195-
ecc_encrypt( pubEcc, data )
196-
{
197-
if ( this.ecc == null || pubEcc.ecc == null )
198-
{
199-
throw 'Ecc not allocated'
200-
}
201-
202-
if ( typeof data == 'string' )
203-
{
204-
data = Buffer.from( data )
205-
}
206-
207-
let cipherText = Buffer.alloc( this.size * 2 + 1 + data.length + 32 )
208-
209-
console.log( cipherText.length )
210-
211-
let ret = wolfcrypt.wc_ecc_encrypt( this.ecc, pubEcc.ecc, data, data.length, cipherText, cipherText.length )
212-
213-
if ( ret <= 0 )
214-
{
215-
throw `Failed to wc_ecc_encrypt ${ ret }`
216-
}
217-
218-
console.log( ret )
219-
220-
cipherText = cipherText.subarray( 0, ret )
221-
222-
return cipherText;
223-
}
224-
225-
ecc_decrypt( pubEcc, cipherText )
226-
{
227-
if ( this.ecc == null || pubEcc.ecc == null )
228-
{
229-
throw 'Ecc not allocated'
230-
}
231-
232-
if ( typeof cipherText == 'string' )
233-
{
234-
cipherText = Buffer.from( cipherText )
235-
}
236-
237-
let data = Buffer.alloc( cipherText.length )
238-
239-
let ret = wolfcrypt.wc_ecc_decrypt( this.ecc, pubEcc.ecc, cipherText, cipherText.length, data, data.length )
240-
241-
if ( ret <= 0 )
242-
{
243-
throw `Failed to wc_ecc_decrypt ${ ret }`
244-
}
245-
246-
data = data.subarray( 0, ret )
247-
248-
return cipherText;
249-
}
250-
251195
free()
252196
{
253197
if ( this.ecc == null )

tests/ecc.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -130,31 +130,6 @@ const ecc_tests =
130130
ecc0.free()
131131
ecc1.free()
132132
},
133-
134-
encryptDecrypt: function()
135-
{
136-
let ecc0 = new WolfSSLEcc()
137-
let ecc1 = new WolfSSLEcc()
138-
let ecc2 = new WolfSSLEcc()
139-
140-
ecc0.make_key( 32 )
141-
ecc1.make_key( 32 )
142-
143-
const cipherText = ecc0.ecc_encrypt( ecc1, message16 )
144-
const plainText = ecc1.ecc_decrypt( ecc2, cipherText ).toString()
145-
146-
if ( plainText == message16 )
147-
{
148-
console.log( 'PASS ecc encryptDecrypt' )
149-
}
150-
else
151-
{
152-
console.log( 'FAIL ecc encryptDecrypt', plainText )
153-
}
154-
155-
ecc0.free()
156-
ecc1.free()
157-
}
158133
}
159134

160135
module.exports = ecc_tests

0 commit comments

Comments
 (0)