static unsigned seckey_length(const pgp_seckey_t *key) { int len; len = 0; switch (key->pubkey.alg) { case PGP_PKA_DSA: return (unsigned)(mpi_length(key->key.dsa.x) + pubkey_length(&key->pubkey)); case PGP_PKA_RSA: len = mpi_length(key->key.rsa.d) + mpi_length(key->key.rsa.p) + mpi_length(key->key.rsa.q) + mpi_length(key->key.rsa.u); return (unsigned)(len + pubkey_length(&key->pubkey)); default: (void) fprintf(stderr, "seckey_length: unknown key algorithm\n"); } return 0; }
static unsigned secret_key_length(const ops_secret_key_t *key) { int l; switch(key->public_key.algorithm) { case OPS_PKA_RSA: l=mpi_length(key->key.rsa.d) +mpi_length(key->key.rsa.p) +mpi_length(key->key.rsa.q) +mpi_length(key->key.rsa.u); break ; case OPS_PKA_DSA: l=mpi_length(key->key.dsa.x); break; default: assert(!"unknown key algorithm"); } return l+public_key_length(&key->public_key); }
static unsigned public_key_length(const ops_public_key_t *key) { switch(key->algorithm) { case OPS_PKA_RSA: return mpi_length(key->key.rsa.n) +mpi_length(key->key.rsa.e); case OPS_PKA_DSA: return mpi_length(key->key.dsa.p) +mpi_length(key->key.dsa.q) +mpi_length(key->key.dsa.g) +mpi_length(key->key.dsa.y); case OPS_PKA_ELGAMAL: return mpi_length(key->key.elgamal.p) +mpi_length(key->key.elgamal.g) +mpi_length(key->key.elgamal.y) ; default: fprintf(stderr,"Bad algorithm type in key: %d\n",key->algorithm) ; assert(!"unknown key algorithm"); } /* not reached */ return 0; }
static unsigned pubkey_length(const pgp_pubkey_t *key) { switch (key->alg) { case PGP_PKA_DSA: return mpi_length(key->key.dsa.p) + mpi_length(key->key.dsa.q) + mpi_length(key->key.dsa.g) + mpi_length(key->key.dsa.y); case PGP_PKA_RSA: return mpi_length(key->key.rsa.n) + mpi_length(key->key.rsa.e); default: (void) fprintf(stderr, "pubkey_length: unknown key algorithm\n"); } return 0; }