6 * Implementation of the EAP-PSK packet management
9 * Copyright (C) France Télécom R&D (DR&D/MAPS/NSS)
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
36 * PSK Packet Format in EAP
37 * --- ------ ------ -- ---
39 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
40 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 * | Code | Identifier | Length |
42 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
49 int pskConvertHex(char *inbytes, char *outstr, int numbytes)
52 char buildstr[1024], tempstr[10];
54 memset(buildstr, 0, 1024);
56 for (i=0;i<numbytes;i++)
58 sprintf((char *)tempstr, "%02X",(unsigned char)inbytes[i]);
59 strcat((char *)buildstr, (char *)tempstr);
61 strcpy(outstr, (char *)buildstr);
67 int pskHex2Bin(const char *hex, unsigned char *bin, int numbytes) {
68 int len = strlen(hex);
72 for (i = 0; i < numbytes; i++) {
74 if (c >= '0' && c <= '9') {
76 } else if (c >= 'A' && c <= 'F') {
78 } else if (c >= 'a' && c <= 'f') {
82 return 0; // non hexa character
86 if (c >= '0' && c <= '9') {
88 } else if (c >= 'A' && c <= 'F') {
90 } else if (c >= 'a' && c <= 'f') {
94 return 0; // non hexa character
102 int pskGetRandomBytes(void *buf, int nbytes){
106 if((fptr = fopen("/dev/urandom","r")) == NULL) {
107 radlog(L_ERR,"pskGetRandomBytes: urandom device not accessible");
111 if((written = fread(buf,1,nbytes,fptr)) != nbytes) {
112 radlog(L_ERR,"pskGetRandomBytes: number not generated");