Die Dokumentation für libgcrypt sagt:Warum sagt gcrypt, den Koeffizienten eines RSA-Schlüssels bei der Konvertierung vom SSL-Format in gcrypt neu zu berechnen?
An RSA private key is described by this S-expression:
(private-key
(rsa
(n n-mpi)
(e e-mpi)
(d d-mpi)
(p p-mpi)
(q q-mpi)
(u u-mpi)))
... und ...
p-mpi
RSA secret prime p.
q-mpi
RSA secret prime q with p < q.
u-mpi
Multiplicative inverse u = p^{-1} mod q.
... und ...
Note that OpenSSL uses slighly different parameters: q < p and u = q^{-1} mod p.
To use these parameters you will need to swap the values and recompute u.
Here is example code to do this:
if (gcry_mpi_cmp (p, q) > 0)
{
gcry_mpi_swap (p, q);
gcry_mpi_invm (u, p, q);
}
Wenn in einem p die kleineren Primzahl und in der anderen q ist die kleinere Primzahl, und da die beiden Gleichungen identisch sind, außer für den Austausch von p und q, ist es wirklich notwendig, müssen Sie neu zu berechnen? Reicht es nicht, nur p und q auszutauschen?
Als Seite Frage, ich bin neugierig, warum gcrypt nicht die gleichen Werte wie die PKCS # 1-Codierung zu verwenden ist:
RSAPrivateKey ::= SEQUENCE {
version Version,
modulus INTEGER, -- n
publicExponent INTEGER, -- e
privateExponent INTEGER, -- d
prime1 INTEGER, -- p
prime2 INTEGER, -- q
exponent1 INTEGER, -- d mod (p-1)
exponent2 INTEGER, -- d mod (q-1)
coefficient INTEGER, -- (inverse of q) mod p
otherPrimeInfos OtherPrimeInfos OPTIONAL
}
o modulus is the RSA modulus n.
o publicExponent is the RSA public exponent e.
o privateExponent is the RSA private exponent d.
o prime1 is the prime factor p of n.
o prime2 is the prime factor q of n.
o exponent1 is d mod (p - 1).
o exponent2 is d mod (q - 1).
o coefficient is the CRT coefficient q^(-1) mod p.
Kann man das nicht einfach mit einem einfachen Experiment selbst herausfinden? –
Wahr. Ich tat. Ich weiß nicht, warum die Dokumentation sagt, "du" neu zu berechnen. Ich benutzte einfach p im Sexp als Wert für q und umgekehrt und es funktioniert gut ... außer dass ich gelegentlich ein Null-Byte vor den entschlüsselten Inhalt gebe. – AlastairG