Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
lowkey.c File Reference
#include "lowkeyi.h"
#include "secoid.h"
#include "secitem.h"
#include "secder.h"
#include "base64.h"
#include "secasn1.h"
#include "pcert.h"
#include "secerr.h"

Go to the source code of this file.

Functions

void prepare_low_rsa_priv_key_for_asn1 (NSSLOWKEYPrivateKey *key)
void prepare_low_pqg_params_for_asn1 (PQGParams *params)
void prepare_low_dsa_priv_key_for_asn1 (NSSLOWKEYPrivateKey *key)
void prepare_low_dsa_priv_key_export_for_asn1 (NSSLOWKEYPrivateKey *key)
void prepare_low_dh_priv_key_for_asn1 (NSSLOWKEYPrivateKey *key)
void nsslowkey_DestroyPrivateKey (NSSLOWKEYPrivateKey *privk)
void nsslowkey_DestroyPublicKey (NSSLOWKEYPublicKey *pubk)
unsigned nsslowkey_PublicModulusLen (NSSLOWKEYPublicKey *pubk)
unsigned nsslowkey_PrivateModulusLen (NSSLOWKEYPrivateKey *privk)
NSSLOWKEYPublicKey * nsslowkey_ConvertToPublicKey (NSSLOWKEYPrivateKey *privk)
NSSLOWKEYPrivateKey * nsslowkey_CopyPrivateKey (NSSLOWKEYPrivateKey *privKey)

Variables

const SEC_ASN1Template nsslowkey_PQGParamsTemplate []
const SEC_ASN1Template nsslowkey_RSAPrivateKeyTemplate []
const SEC_ASN1Template nsslowkey_DSAPrivateKeyTemplate []
const SEC_ASN1Template nsslowkey_DSAPrivateKeyExportTemplate []
const SEC_ASN1Template nsslowkey_DHPrivateKeyTemplate []

Function Documentation

NSSLOWKEYPublicKey* nsslowkey_ConvertToPublicKey ( NSSLOWKEYPrivateKey *  privk)

Definition at line 267 of file lowkey.c.

{
    NSSLOWKEYPublicKey *pubk;
    PLArenaPool *arena;


    arena = PORT_NewArena (DER_DEFAULT_CHUNKSIZE);
    if (arena == NULL) {
        PORT_SetError (SEC_ERROR_NO_MEMORY);
        return NULL;
    }

    switch(privk->keyType) {
      case NSSLOWKEYRSAKey:
      case NSSLOWKEYNullKey:
       pubk = (NSSLOWKEYPublicKey *)PORT_ArenaZAlloc(arena,
                                          sizeof (NSSLOWKEYPublicKey));
       if (pubk != NULL) {
           SECStatus rv;

           pubk->arena = arena;
           pubk->keyType = privk->keyType;
           if (privk->keyType == NSSLOWKEYNullKey) return pubk;
           rv = SECITEM_CopyItem(arena, &pubk->u.rsa.modulus,
                              &privk->u.rsa.modulus);
           if (rv == SECSuccess) {
              rv = SECITEM_CopyItem (arena, &pubk->u.rsa.publicExponent,
                                   &privk->u.rsa.publicExponent);
              if (rv == SECSuccess)
                  return pubk;
           }
       } else {
           PORT_SetError (SEC_ERROR_NO_MEMORY);
       }
       break;
      case NSSLOWKEYDSAKey:
       pubk = (NSSLOWKEYPublicKey *)PORT_ArenaZAlloc(arena,
                                              sizeof(NSSLOWKEYPublicKey));
       if (pubk != NULL) {
           SECStatus rv;

           pubk->arena = arena;
           pubk->keyType = privk->keyType;
           rv = SECITEM_CopyItem(arena, &pubk->u.dsa.publicValue,
                              &privk->u.dsa.publicValue);
           if (rv != SECSuccess) break;
           rv = SECITEM_CopyItem(arena, &pubk->u.dsa.params.prime,
                              &privk->u.dsa.params.prime);
           if (rv != SECSuccess) break;
           rv = SECITEM_CopyItem(arena, &pubk->u.dsa.params.subPrime,
                              &privk->u.dsa.params.subPrime);
           if (rv != SECSuccess) break;
           rv = SECITEM_CopyItem(arena, &pubk->u.dsa.params.base,
                              &privk->u.dsa.params.base);
           if (rv == SECSuccess) return pubk;
       }
       break;
      case NSSLOWKEYDHKey:
       pubk = (NSSLOWKEYPublicKey *)PORT_ArenaZAlloc(arena,
                                              sizeof(NSSLOWKEYPublicKey));
       if (pubk != NULL) {
           SECStatus rv;

           pubk->arena = arena;
           pubk->keyType = privk->keyType;
           rv = SECITEM_CopyItem(arena, &pubk->u.dh.publicValue,
                              &privk->u.dh.publicValue);
           if (rv != SECSuccess) break;
           rv = SECITEM_CopyItem(arena, &pubk->u.dh.prime,
                              &privk->u.dh.prime);
           if (rv != SECSuccess) break;
           rv = SECITEM_CopyItem(arena, &pubk->u.dh.base,
                              &privk->u.dh.base);
           if (rv == SECSuccess) return pubk;
       }
       break;
#ifdef NSS_ENABLE_ECC
      case NSSLOWKEYECKey:
       pubk = (NSSLOWKEYPublicKey *)PORT_ArenaZAlloc(arena,
                                              sizeof(NSSLOWKEYPublicKey));
       if (pubk != NULL) {
           SECStatus rv;

           pubk->arena = arena;
           pubk->keyType = privk->keyType;
           rv = SECITEM_CopyItem(arena, &pubk->u.ec.publicValue,
                              &privk->u.ec.publicValue);
           if (rv != SECSuccess) break;
           pubk->u.ec.ecParams.arena = arena;
           /* Copy the rest of the params */
           rv = EC_CopyParams(arena, &(pubk->u.ec.ecParams),
                            &(privk->u.ec.ecParams));
           if (rv == SECSuccess) return pubk;
       }
       break;
#endif /* NSS_ENABLE_ECC */
       /* No Fortezza in Low Key implementations (Fortezza keys aren't
        * stored in our data base */
    default:
       break;
    }

    PORT_FreeArena (arena, PR_FALSE);
    return NULL;
}

Here is the call graph for this function:

NSSLOWKEYPrivateKey* nsslowkey_CopyPrivateKey ( NSSLOWKEYPrivateKey *  privKey)

Definition at line 374 of file lowkey.c.

{
    NSSLOWKEYPrivateKey *returnKey = NULL;
    SECStatus rv = SECFailure;
    PLArenaPool *poolp;

    if(!privKey) {
       return NULL;
    }

    poolp = PORT_NewArena(DER_DEFAULT_CHUNKSIZE);
    if(!poolp) {
       return NULL;
    }

    returnKey = (NSSLOWKEYPrivateKey*)PORT_ArenaZAlloc(poolp, sizeof(NSSLOWKEYPrivateKey));
    if(!returnKey) {
       rv = SECFailure;
       goto loser;
    }

    returnKey->keyType = privKey->keyType;
    returnKey->arena = poolp;

    switch(privKey->keyType) {
       case NSSLOWKEYRSAKey:
           rv = SECITEM_CopyItem(poolp, &(returnKey->u.rsa.modulus), 
                                   &(privKey->u.rsa.modulus));
           if(rv != SECSuccess) break;
           rv = SECITEM_CopyItem(poolp, &(returnKey->u.rsa.version), 
                                   &(privKey->u.rsa.version));
           if(rv != SECSuccess) break;
           rv = SECITEM_CopyItem(poolp, &(returnKey->u.rsa.publicExponent), 
                                   &(privKey->u.rsa.publicExponent));
           if(rv != SECSuccess) break;
           rv = SECITEM_CopyItem(poolp, &(returnKey->u.rsa.privateExponent), 
                                   &(privKey->u.rsa.privateExponent));
           if(rv != SECSuccess) break;
           rv = SECITEM_CopyItem(poolp, &(returnKey->u.rsa.prime1), 
                                   &(privKey->u.rsa.prime1));
           if(rv != SECSuccess) break;
           rv = SECITEM_CopyItem(poolp, &(returnKey->u.rsa.prime2), 
                                   &(privKey->u.rsa.prime2));
           if(rv != SECSuccess) break;
           rv = SECITEM_CopyItem(poolp, &(returnKey->u.rsa.exponent1), 
                                   &(privKey->u.rsa.exponent1));
           if(rv != SECSuccess) break;
           rv = SECITEM_CopyItem(poolp, &(returnKey->u.rsa.exponent2), 
                                   &(privKey->u.rsa.exponent2));
           if(rv != SECSuccess) break;
           rv = SECITEM_CopyItem(poolp, &(returnKey->u.rsa.coefficient), 
                                   &(privKey->u.rsa.coefficient));
           if(rv != SECSuccess) break;
           break;
       case NSSLOWKEYDSAKey:
           rv = SECITEM_CopyItem(poolp, &(returnKey->u.dsa.publicValue),
                                   &(privKey->u.dsa.publicValue));
           if(rv != SECSuccess) break;
           rv = SECITEM_CopyItem(poolp, &(returnKey->u.dsa.privateValue),
                                   &(privKey->u.dsa.privateValue));
           if(rv != SECSuccess) break;
           returnKey->u.dsa.params.arena = poolp;
           rv = SECITEM_CopyItem(poolp, &(returnKey->u.dsa.params.prime),
                                   &(privKey->u.dsa.params.prime));
           if(rv != SECSuccess) break;
           rv = SECITEM_CopyItem(poolp, &(returnKey->u.dsa.params.subPrime),
                                   &(privKey->u.dsa.params.subPrime));
           if(rv != SECSuccess) break;
           rv = SECITEM_CopyItem(poolp, &(returnKey->u.dsa.params.base),
                                   &(privKey->u.dsa.params.base));
           if(rv != SECSuccess) break;
           break;
       case NSSLOWKEYDHKey:
           rv = SECITEM_CopyItem(poolp, &(returnKey->u.dh.publicValue),
                                   &(privKey->u.dh.publicValue));
           if(rv != SECSuccess) break;
           rv = SECITEM_CopyItem(poolp, &(returnKey->u.dh.privateValue),
                                   &(privKey->u.dh.privateValue));
           if(rv != SECSuccess) break;
           returnKey->u.dsa.params.arena = poolp;
           rv = SECITEM_CopyItem(poolp, &(returnKey->u.dh.prime),
                                   &(privKey->u.dh.prime));
           if(rv != SECSuccess) break;
           rv = SECITEM_CopyItem(poolp, &(returnKey->u.dh.base),
                                   &(privKey->u.dh.base));
           if(rv != SECSuccess) break;
           break;
#ifdef NSS_ENABLE_ECC
       case NSSLOWKEYECKey:
           rv = SECITEM_CopyItem(poolp, &(returnKey->u.ec.version),
                                   &(privKey->u.ec.version));
           if(rv != SECSuccess) break;
           rv = SECITEM_CopyItem(poolp, &(returnKey->u.ec.publicValue),
                                   &(privKey->u.ec.publicValue));
           if(rv != SECSuccess) break;
           rv = SECITEM_CopyItem(poolp, &(returnKey->u.ec.privateValue),
                                   &(privKey->u.ec.privateValue));
           if(rv != SECSuccess) break;
           returnKey->u.ec.ecParams.arena = poolp;
           /* Copy the rest of the params */
           rv = EC_CopyParams(poolp, &(returnKey->u.ec.ecParams),
                            &(privKey->u.ec.ecParams));
           if (rv != SECSuccess) break;
           break;
#endif /* NSS_ENABLE_ECC */
       default:
           rv = SECFailure;
    }

loser:

    if(rv != SECSuccess) {
       PORT_FreeArena(poolp, PR_TRUE);
       returnKey = NULL;
    }

    return returnKey;
}

Here is the call graph for this function:

void nsslowkey_DestroyPrivateKey ( NSSLOWKEYPrivateKey *  privk)

Definition at line 218 of file lowkey.c.

{
    if (privk && privk->arena) {
       PORT_FreeArena(privk->arena, PR_TRUE);
    }
}

Here is the call graph for this function:

void nsslowkey_DestroyPublicKey ( NSSLOWKEYPublicKey *  pubk)

Definition at line 226 of file lowkey.c.

{
    if (pubk && pubk->arena) {
       PORT_FreeArena(pubk->arena, PR_FALSE);
    }
}

Here is the call graph for this function:

unsigned nsslowkey_PrivateModulusLen ( NSSLOWKEYPrivateKey *  privk)

Definition at line 251 of file lowkey.c.

{

    unsigned char b0;

    switch (privk->keyType) {
    case NSSLOWKEYRSAKey:
       b0 = privk->u.rsa.modulus.data[0];
       return b0 ? privk->u.rsa.modulus.len : privk->u.rsa.modulus.len - 1;
    default:
       break;
    }
    return 0;
}
unsigned nsslowkey_PublicModulusLen ( NSSLOWKEYPublicKey *  pubk)

Definition at line 233 of file lowkey.c.

{
    unsigned char b0;

    /* interpret modulus length as key strength... in
     * fortezza that's the public key length */

    switch (pubk->keyType) {
    case NSSLOWKEYRSAKey:
       b0 = pubk->u.rsa.modulus.data[0];
       return b0 ? pubk->u.rsa.modulus.len : pubk->u.rsa.modulus.len - 1;
    default:
       break;
    }
    return 0;
}
void prepare_low_dh_priv_key_for_asn1 ( NSSLOWKEYPrivateKey *  key)

Definition at line 190 of file lowkey.c.

{
    key->u.dh.prime.type = siUnsignedInteger;
    key->u.dh.base.type = siUnsignedInteger;
    key->u.dh.publicValue.type = siUnsignedInteger;
    key->u.dh.privateValue.type = siUnsignedInteger;
}
void prepare_low_dsa_priv_key_export_for_asn1 ( NSSLOWKEYPrivateKey *  key)

Definition at line 184 of file lowkey.c.

{
    key->u.dsa.privateValue.type = siUnsignedInteger;
}
void prepare_low_dsa_priv_key_for_asn1 ( NSSLOWKEYPrivateKey *  key)

Definition at line 174 of file lowkey.c.

{
    key->u.dsa.publicValue.type = siUnsignedInteger;
    key->u.dsa.privateValue.type = siUnsignedInteger;
    key->u.dsa.params.prime.type = siUnsignedInteger;
    key->u.dsa.params.subPrime.type = siUnsignedInteger;
    key->u.dsa.params.base.type = siUnsignedInteger;
}
void prepare_low_pqg_params_for_asn1 ( PQGParams *  params)

Definition at line 166 of file lowkey.c.

{
    params->prime.type = siUnsignedInteger;
    params->subPrime.type = siUnsignedInteger;
    params->base.type = siUnsignedInteger;
}
void prepare_low_rsa_priv_key_for_asn1 ( NSSLOWKEYPrivateKey *  key)

Definition at line 153 of file lowkey.c.

{
    key->u.rsa.modulus.type = siUnsignedInteger;
    key->u.rsa.publicExponent.type = siUnsignedInteger;
    key->u.rsa.privateExponent.type = siUnsignedInteger;
    key->u.rsa.prime1.type = siUnsignedInteger;
    key->u.rsa.prime2.type = siUnsignedInteger;
    key->u.rsa.exponent1.type = siUnsignedInteger;
    key->u.rsa.exponent2.type = siUnsignedInteger;
    key->u.rsa.coefficient.type = siUnsignedInteger;
}

Variable Documentation

Initial value:
 {
    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(NSSLOWKEYPrivateKey) },
    { SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.dh.publicValue) },
    { SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.dh.privateValue) },
    { SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.dh.base) },
    { SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.dh.prime) },
    { 0, }
}

Definition at line 86 of file lowkey.c.

Initial value:
 {
    { SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.dsa.privateValue) },
}

Definition at line 82 of file lowkey.c.

Initial value:
 {
    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(NSSLOWKEYPrivateKey) },
    { SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.dsa.publicValue) },
    { SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.dsa.privateValue) },
    { 0, }
}

Definition at line 75 of file lowkey.c.

Initial value:
 {
    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(PQGParams) },
    { SEC_ASN1_INTEGER, offsetof(PQGParams,prime) },
    { SEC_ASN1_INTEGER, offsetof(PQGParams,subPrime) },
    { SEC_ASN1_INTEGER, offsetof(PQGParams,base) },
    { 0, }
}

Definition at line 52 of file lowkey.c.

Initial value:
 {
    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(NSSLOWKEYPrivateKey) },
    { SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.rsa.version) },
    { SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.rsa.modulus) },
    { SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.rsa.publicExponent) },
    { SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.rsa.privateExponent) },
    { SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.rsa.prime1) },
    { SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.rsa.prime2) },
    { SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.rsa.exponent1) },
    { SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.rsa.exponent2) },
    { SEC_ASN1_INTEGER, offsetof(NSSLOWKEYPrivateKey,u.rsa.coefficient) },
    { 0 }                                                                     
}

Definition at line 60 of file lowkey.c.