The Group Parameters are in a file in DER / ASN1 format. The format is
as in PKCS#3 dhKeyAgreement that looks like:
SEQUENCE
INTEGER - Prime - p
INTEGER - Group Generator - g
INTEGER - Private Key Length
Once loaded into an array of BYTE, they look like this in memory:
30 82 01 0B 02 81 81 00 DC B5 54 DF 8C 69 31 E8
65 C1 B5 88 27 3D 80 A2 D8 7A B5 39 C5 E4 A0 74
B4 02 49 FF 65 5A 9A B8 30 63 3B 45 7C 4C F8 85
E3 1C D7 9F 81 14 8C 8A 68 D1 DB FC 2F 7B 70 ED
55 C0 38 7C 23 A0 47 9A 95 72 E8 A6 71 4F 41 8A
6B F9 B0 0E C5 BC 4D EF 25 5A 94 85 05 8A 42 71
00 8B A6 94 AA 62 CC 18 38 5E F9 D7 B6 E8 33 A7
08 8A C8 17 AA 1F 9B 93 A8 6B 98 3E AB 73 C1 58
84 E7 33 66 56 59 CA 7D 02 81 80 2E 69 FE 94 D3
C0 A4 37 8C 8A 47 9D 83 09 1A ED 41 92 34 25 C1
03 00 8C 6A B3 F6 E8 3E 20 CB 16 C4 AE 0B 0E 28
ED 9B C7 9C D7 D7 E9 DF D3 9D D0 A3 91 41 F2 DD
57 14 9A B6 88 DB AD 17 7C 68 6F 77 18 28 E5 A0
44 08 51 2F 15 64 74 B0 BF D4 30 CB BF 91 C0 15
89 E7 21 DD DF FC DF 45 00 43 EB 77 1E 61 08 4C
59 7F 7A EA 90 48 42 0A 21 80 EB FE C1 B3 B9 3C
1A 6C B1 AD 38 B3 98 4F F0 52 10 02 02 03 F9
My problem is coding to load this into the DH object. For example:
BYTE GroupParameters[] = {0x30, 0x30, 0x82, 0x01, 0x0B,...}; <--
all bytes above
DH dh;
How do I tell "dh" to take the GroupParameters??
I have tried:
DH dh(StringSource(GroupParameters, GroupParametersLen, true, NULL));
but it does not seem to work latter on (I mean, it does not complain
about it, but the Agree function does not work latter on).
Christian
BYTE DPPrime[] = {0x02, 0x81, 0x81, 0x00, 0xDC,.....}; // holds 'p'
BYTE DPGenerator[] = {0x02, 0x80, 0x80, 0x2E, 0x69,.....}; // holds
'g'
Integer iPrime, iGenerator;
std::string sP(reinterpret_cast<const char *>(DPPrime),
DPPrimeLength);
iPrime.BERDecode(StringStore(sP).Ref());
std::string sG(reinterpret_cast<const char *>(DPGenerator),
DPGeneratorLength);
iGenerator.BERDecode(StringStore(sG).Ref());
DH dh(iPrime, iGenerator);
...
...
...
So the whole problem was really passing correct p and g to the DH
class.
Christian
DH_Domain(BufferedTransformation &bt)
{m_groupParameters.BERDecode(bt);}
see also gfpcrypt.cpp:
void DL_GroupParameters_IntegerBased::BERDecode(BufferedTransformation &bt)