18 #include "cryptdefs_p.h"
19 #include <gwenhywfar/misc.h>
20 #include <gwenhywfar/debug.h>
22 #include <gwenhywfar/mdigest.h>
31 if (strcasecmp(s,
"none")==0)
33 else if (strcasecmp(s,
"access")==0)
35 else if (strcasecmp(s,
"manage")==0)
59 if (strcasecmp(s,
"none")==0)
61 else if (strcasecmp(s,
"bin")==0)
63 else if (strcasecmp(s,
"bcd")==0)
65 else if (strcasecmp(s,
"ascii")==0)
67 else if (strcasecmp(s,
"fpin2")==0)
94 unsigned int bufLength,
95 unsigned int *pinLength) {
96 unsigned char *newBuf;
105 newSize=*pinLength*2;
106 newBuf=(
unsigned char*)malloc(newSize);
108 for (i=0; i<*pinLength; i++) {
134 memset(buffer, 0, bufLength);
135 memmove(buffer, newBuf, cnt);
144 unsigned int bufLength,
145 unsigned int *pinLength) {
146 unsigned char *newBuf;
148 unsigned int newSize;
157 len=(buffer[0] & 0x0f);
159 newBuf=(
unsigned char*)malloc(newSize);
161 for (i=1; i<8; i++) {
193 memset(buffer, 0, bufLength);
194 memmove(buffer, newBuf, cnt);
202 unsigned int bufLength,
203 unsigned int *pinLength) {
205 unsigned char *newBuf;
207 unsigned int newSize;
213 newBuf=(
unsigned char*)malloc(newSize);
216 for (i=0; i<*pinLength; i++) {
227 memset(buffer, 0, bufLength);
228 memmove(buffer, newBuf, *pinLength);
237 unsigned int bufLength,
238 unsigned int *pinLength) {
239 unsigned char *newBuf;
241 unsigned int newSize;
245 newSize=*pinLength/2+1;
246 newBuf=(
unsigned char*)malloc(newSize);
247 memset(newBuf, 0xff, newSize);
250 while (i<*pinLength) {
256 if (c1<'0' || c1>
'9') {
271 if (c2<'0' || c2>
'9') {
289 memset(buffer, 0, bufLength);
290 for (i=0; i<cnt; i++)
300 unsigned int bufLength,
301 unsigned int *pinLength) {
302 unsigned char *newBuf;
304 unsigned int newSize;
319 newBuf=(
unsigned char*)malloc(newSize);
320 memset(newBuf, 0xff, newSize);
322 *(p++)=0x20+*pinLength;
324 while (i<*pinLength) {
330 if (c1<'0' || c1>
'9') {
344 if (c2<'0' || c2>
'9') {
355 memset(buffer, 0, bufLength);
367 unsigned int bufLength,
368 unsigned int *pinLength) {
370 unsigned char *newBuf;
372 unsigned int newSize;
378 newBuf=(
unsigned char*)malloc(newSize);
381 for (i=0; i<*pinLength; i++) {
385 if (c<'0' || c>
'9') {
392 memset(buffer, 0, bufLength);
393 memmove(buffer, newBuf, *pinLength);
403 unsigned char *buffer,
404 unsigned int bufLength,
405 unsigned int *pinLength) {
426 "Unhandled source encoding \"%s\"",
450 "Unhandled destination encoding \"%s\"",
466 unsigned char *buffer,
467 unsigned int bufLength) {
491 (
const uint8_t*)text,
517 unsigned char *buffer,
518 unsigned int bufLength) {
525 memmove(buffer+16, buffer, 8);
536 enum gcry_random_level q;
539 case 0: q=GCRY_WEAK_RANDOM;
break;
540 case 1: q=GCRY_STRONG_RANDOM;
break;
542 default: q=GCRY_VERY_STRONG_RANDOM;
break;
545 data=gcry_random_bytes(len, q);
547 memmove(buffer, data, len);
548 memset(data, 0, len);