16 #define BITS_PER_GROUP ( 5 * 5 )
20 static const char codeTable[] = \
21 "ABCDEFGHJKLMNPQRSTUVWXYZ23456789____";
22 static const int hiMask[] = { 0x00, 0x00, 0x00, 0x00, 0x0F, 0x07, 0x03, 0x01 };
23 static const int loMask[] = { 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0 };
43 IN_RANGE( 3, 4 )
const int noCodeGroups )
46 assert(
isWritePtr( valueLength,
sizeof(
int ) ) );
50 REQUIRES( noCodeGroups == 3 || noCodeGroups == 4 );
54 if( noCodeGroups == 3 )
88 IN_RANGE( 3, 4 )
const int noCodeGroups )
90 BYTE valBuf[ 128 + 8 ];
95 assert(
isWritePtr( encValLen,
sizeof(
int ) ) );
100 REQUIRES( noCodeGroups == 3 || noCodeGroups == 4 );
101 REQUIRES( dataBytes >= 10 && dataBytes < 64 );
102 REQUIRES( valueLen >= dataBytes - 1 );
108 memset( encVal, 0,
min( 16, encValMaxLen ) );
113 memcpy( valBuf + 1, value, dataBytes - 1 );
114 status = adjustPKIUserValue( valBuf + 1, 128 - 1, &
length,
123 valBuf[ 0 ] =
intToByte( checksumData( valBuf + 1,
length - 1 ) & 0xFF );
126 for(
length = 0, i = 1; i <= noCodeGroups * 5; i++ )
134 chunkValue = ( valBuf[ byteCount ] >> ( 3 - bitCount ) ) & 0x1F;
141 chunkValue = valBuf[ byteCount ] & 0x1F;
147 chunkValue = ( ( valBuf[ byteCount ] & \
148 hiMask[ bitCount ] ) << ( bitCount - 3 ) ) | \
149 ( ( valBuf[ byteCount + 1 ] & \
150 loMask[ bitCount ] ) >> ( 11 - bitCount ) );
153 ENSURES( chunkValue >= 0 && chunkValue <= 0x20 );
154 encVal[
length++ ] = codeTable[ chunkValue ];
155 if(
length < encValMaxLen && ( i % 5 ) == 0 && i < noCodeGroups * 5 )
166 ENSURES( byteCount >= 0 && byteCount < 64 );
187 assert(
isReadPtr( encVal, encValLength ) );
197 if( ( encValLength != ( 3 * 5 ) + 2 ) && \
198 ( encValLength != ( 4 * 5 ) + 3 ) )
200 while( i < encValLength )
207 for( j = 0; j < 5; j++ )
214 if( i < encValLength && encVal[ i++ ] !=
'-' )
223 int decodePKIUserValue(
OUT_BUFFER( valueMaxLen, *valueLen )
BYTE *value,
229 BYTE valBuf[ 128 + 8 ];
231 int i = 0, byteCount = 0, bitCount = 0,
length = 0;
234 assert(
isWritePtr( valueLen,
sizeof(
int ) ) );
235 assert(
isReadPtr( encVal, encValLength ) );
241 memset( value, 0,
min( 16, valueMaxLen ) );
252 DEBUG_DIAG((
"PKI user value has invalid length" ));
257 REQUIRES( isPKIUserValue( encVal, encValLength ) );
261 while( i < encValLength )
265 for( j = 0; j < 5; j++ )
271 if( !
isAlnum( ch ) || i > encValLength )
275 if( i < encValLength && encVal[ i++ ] !=
'-' )
282 memset( valBuf, 0, 128 );
283 for( i = 0; i <
length; i ++ )
288 for( chunkValue = 0; chunkValue < 0x20; chunkValue++ )
290 if( codeTable[ chunkValue ] == ch )
293 if( chunkValue >= 0x20 )
300 valBuf[ byteCount ] |= chunkValue << ( 3 - bitCount );
307 valBuf[ byteCount ] |= chunkValue;
313 valBuf[ byteCount ] |= \
314 intToByte( ( chunkValue >> ( bitCount - 3 ) ) & \
315 hiMask[ bitCount ] );
316 valBuf[ byteCount + 1 ] = \
317 intToByte( ( chunkValue << ( 11 - bitCount ) ) & \
318 loMask[ bitCount ] );
329 ENSURES( byteCount >= 0 && byteCount < 64 );
336 if( valBuf[ 0 ] != ( checksumData( valBuf + 1, byteCount - 1 ) & 0xFF ) )
340 ENSURES( byteCount - 1 <= valueMaxLen );
341 memcpy( value, valBuf + 1, byteCount - 1 );
342 *valueLen = byteCount - 1;