299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
|
/* NOTREACH */
clientData = clientData;
}
static int nano_tcl_hash_data(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) {
unsigned char *data, result[crypto_sign_BYTES];
int data_length, result_length;
if (objc != 2) {
Tcl_WrongNumArgs(interp, 1, objv, "data");
return(TCL_ERROR);
}
data = Tcl_GetByteArrayFromObj(objv[1], &data_length);
crypto_hash(result, data, data_length);
result_length = crypto_sign_BYTES;
Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(result, result_length));
return(TCL_OK);
/* NOTREACH */
clientData = clientData;
}
|
>
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
>
>
|
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
|
/* NOTREACH */
clientData = clientData;
}
static int nano_tcl_hash_data(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) {
unsigned char *data, result[crypto_sign_BYTES];
int tgifo_ret;
int data_length, result_length;
if (objc < 2 || objc > 3) {
Tcl_WrongNumArgs(interp, 1, objv, "data ?hashLength?");
return(TCL_ERROR);
}
data = Tcl_GetByteArrayFromObj(objv[1], &data_length);
if (objc == 3) {
tgifo_ret = Tcl_GetIntFromObj(interp, objv[2], &result_length);
if (tgifo_ret != TCL_OK) {
return(tgifo_ret);
}
if (result_length > sizeof(result)) {
Tcl_SetResult(interp, "Hash length too large", NULL);
return(TCL_ERROR);
}
blake2b(result, result_length, data, data_length, NULL, 0);
} else {
/*
* Default to the same as the cryptographic primitive
*/
crypto_hash(result, data, data_length);
result_length = crypto_sign_BYTES;
}
Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(result, result_length));
return(TCL_OK);
/* NOTREACH */
clientData = clientData;
}
|
332
333
334
335
336
337
338
339
340
341
342
343
344
345
|
return(TCL_OK);
/* NOTREACH */
clientData = clientData;
}
int Nano_Init(Tcl_Interp *interp) {
const char nanoInitScript[] = {
#include "nano.tcl.h"
0x00
};
#ifdef USE_TCL_STUBS
const char *tclInitStubs_ret;
|
>
|
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
|
return(TCL_OK);
/* NOTREACH */
clientData = clientData;
}
int Nano_Init(Tcl_Interp *interp) {
int te_ret;
const char nanoInitScript[] = {
#include "nano.tcl.h"
0x00
};
#ifdef USE_TCL_STUBS
const char *tclInitStubs_ret;
|
354
355
356
357
358
359
360
361
362
363
364
365
|
Tcl_CreateObjCommand(interp, "::nano::internal::generateKey", nano_tcl_generate_keypair, NULL, NULL);
Tcl_CreateObjCommand(interp, "::nano::internal::signDetached", nano_tcl_sign_detached, NULL, NULL);
Tcl_CreateObjCommand(interp, "::nano::internal::publicKey", nano_tcl_secret_key_to_public_key, NULL, NULL);
Tcl_CreateObjCommand(interp, "::nano::internal::verifyDetached", nano_tcl_verify_detached, NULL, NULL);
Tcl_CreateObjCommand(interp, "::nano::internal::hashData", nano_tcl_hash_data, NULL, NULL);
if (interp) {
Tcl_Eval(interp, nanoInitScript);
}
return(TCL_OK);
}
|
|
>
>
>
|
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
|
Tcl_CreateObjCommand(interp, "::nano::internal::generateKey", nano_tcl_generate_keypair, NULL, NULL);
Tcl_CreateObjCommand(interp, "::nano::internal::signDetached", nano_tcl_sign_detached, NULL, NULL);
Tcl_CreateObjCommand(interp, "::nano::internal::publicKey", nano_tcl_secret_key_to_public_key, NULL, NULL);
Tcl_CreateObjCommand(interp, "::nano::internal::verifyDetached", nano_tcl_verify_detached, NULL, NULL);
Tcl_CreateObjCommand(interp, "::nano::internal::hashData", nano_tcl_hash_data, NULL, NULL);
if (interp) {
te_ret = Tcl_Eval(interp, nanoInitScript);
if (te_ret != TCL_OK) {
return(te_ret);
}
}
return(TCL_OK);
}
|