michael@0: /* michael@0: * blapi.h - public prototypes for the freebl library michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef _BLAPI_H_ michael@0: #define _BLAPI_H_ michael@0: michael@0: #include "blapit.h" michael@0: #include "hasht.h" michael@0: #include "alghmac.h" michael@0: michael@0: SEC_BEGIN_PROTOS michael@0: michael@0: /* michael@0: ** RSA encryption/decryption. When encrypting/decrypting the output michael@0: ** buffer must be at least the size of the public key modulus. michael@0: */ michael@0: michael@0: extern SECStatus BL_Init(void); michael@0: michael@0: /* michael@0: ** Generate and return a new RSA public and private key. michael@0: ** Both keys are encoded in a single RSAPrivateKey structure. michael@0: ** "cx" is the random number generator context michael@0: ** "keySizeInBits" is the size of the key to be generated, in bits. michael@0: ** 512, 1024, etc. michael@0: ** "publicExponent" when not NULL is a pointer to some data that michael@0: ** represents the public exponent to use. The data is a byte michael@0: ** encoded integer, in "big endian" order. michael@0: */ michael@0: extern RSAPrivateKey *RSA_NewKey(int keySizeInBits, michael@0: SECItem * publicExponent); michael@0: michael@0: /* michael@0: ** Perform a raw public-key operation michael@0: ** Length of input and output buffers are equal to key's modulus len. michael@0: */ michael@0: extern SECStatus RSA_PublicKeyOp(RSAPublicKey * key, michael@0: unsigned char * output, michael@0: const unsigned char * input); michael@0: michael@0: /* michael@0: ** Perform a raw private-key operation michael@0: ** Length of input and output buffers are equal to key's modulus len. michael@0: */ michael@0: extern SECStatus RSA_PrivateKeyOp(RSAPrivateKey * key, michael@0: unsigned char * output, michael@0: const unsigned char * input); michael@0: michael@0: /* michael@0: ** Perform a raw private-key operation, and check the parameters used in michael@0: ** the operation for validity by performing a test operation first. michael@0: ** Length of input and output buffers are equal to key's modulus len. michael@0: */ michael@0: extern SECStatus RSA_PrivateKeyOpDoubleChecked(RSAPrivateKey * key, michael@0: unsigned char * output, michael@0: const unsigned char * input); michael@0: michael@0: /* michael@0: ** Perform a check of private key parameters for consistency. michael@0: */ michael@0: extern SECStatus RSA_PrivateKeyCheck(const RSAPrivateKey *key); michael@0: michael@0: /* michael@0: ** Given only minimal private key parameters, fill in the rest of the michael@0: ** parameters. michael@0: ** michael@0: ** michael@0: ** All the entries, including those supplied by the caller, will be michael@0: ** overwritten with data alocated out of the arena. michael@0: ** michael@0: ** If no arena is supplied, one will be created. michael@0: ** michael@0: ** The following fields must be supplied in order for this function michael@0: ** to succeed: michael@0: ** one of either publicExponent or privateExponent michael@0: ** two more of the following 5 parameters (not counting the above). michael@0: ** modulus (n) michael@0: ** prime1 (p) michael@0: ** prime2 (q) michael@0: ** publicExponent (e) michael@0: ** privateExponent (d) michael@0: ** michael@0: ** NOTE: if only the publicExponent, privateExponent, and one prime is given, michael@0: ** then there may be more than one RSA key that matches that combination. If michael@0: ** we find 2 possible valid keys that meet this criteria, we return an error. michael@0: ** If we return the wrong key, and the original modulus is compared to the michael@0: ** new modulus, both can be factored by calculateing gcd(n_old,n_new) to get michael@0: ** the common prime. michael@0: ** michael@0: ** NOTE: in some cases the publicExponent must be less than 2^23 for this michael@0: ** function to work correctly. (The case where we have only one of: modulus michael@0: ** prime1 and prime2). michael@0: ** michael@0: ** All parameters will be replaced in the key structure with new parameters michael@0: ** allocated out of the arena. There is no attempt to free the old structures. michael@0: ** prime1 will always be greater than prime2 (even if the caller supplies the michael@0: ** smaller prime as prime1 or the larger prime as prime2). The parameters are michael@0: ** not overwritten on failure. michael@0: ** michael@0: ** While the remaining Chinese remainder theorem parameters (dp,dp, and qinv) michael@0: ** can also be used in reconstructing the private key, they are currently michael@0: ** ignored in this implementation. michael@0: */ michael@0: extern SECStatus RSA_PopulatePrivateKey(RSAPrivateKey *key); michael@0: michael@0: /******************************************************************** michael@0: ** RSA algorithm michael@0: */ michael@0: michael@0: /******************************************************************** michael@0: ** Raw signing/encryption/decryption operations. michael@0: ** michael@0: ** No padding or formatting will be applied. michael@0: ** inputLen MUST be equivalent to the modulus size (in bytes). michael@0: */ michael@0: extern SECStatus michael@0: RSA_SignRaw(RSAPrivateKey * key, michael@0: unsigned char * output, michael@0: unsigned int * outputLen, michael@0: unsigned int maxOutputLen, michael@0: const unsigned char * input, michael@0: unsigned int inputLen); michael@0: michael@0: extern SECStatus michael@0: RSA_CheckSignRaw(RSAPublicKey * key, michael@0: const unsigned char * sig, michael@0: unsigned int sigLen, michael@0: const unsigned char * hash, michael@0: unsigned int hashLen); michael@0: michael@0: extern SECStatus michael@0: RSA_CheckSignRecoverRaw(RSAPublicKey * key, michael@0: unsigned char * data, michael@0: unsigned int * dataLen, michael@0: unsigned int maxDataLen, michael@0: const unsigned char * sig, michael@0: unsigned int sigLen); michael@0: michael@0: extern SECStatus michael@0: RSA_EncryptRaw(RSAPublicKey * key, michael@0: unsigned char * output, michael@0: unsigned int * outputLen, michael@0: unsigned int maxOutputLen, michael@0: const unsigned char * input, michael@0: unsigned int inputLen); michael@0: michael@0: extern SECStatus michael@0: RSA_DecryptRaw(RSAPrivateKey * key, michael@0: unsigned char * output, michael@0: unsigned int * outputLen, michael@0: unsigned int maxOutputLen, michael@0: const unsigned char * input, michael@0: unsigned int inputLen); michael@0: michael@0: /******************************************************************** michael@0: ** RSAES-OAEP encryption/decryption, as defined in RFC 3447, Section 7.1. michael@0: ** michael@0: ** Note: Only MGF1 is supported as the mask generation function. It will be michael@0: ** used with maskHashAlg as the inner hash function. michael@0: ** michael@0: ** Unless performing Known Answer Tests, "seed" should be NULL, indicating that michael@0: ** freebl should generate a random value. Otherwise, it should be an octet michael@0: ** string of seedLen bytes, which should be the same size as the output of michael@0: ** hashAlg. michael@0: */ michael@0: extern SECStatus michael@0: RSA_EncryptOAEP(RSAPublicKey * key, michael@0: HASH_HashType hashAlg, michael@0: HASH_HashType maskHashAlg, michael@0: const unsigned char * label, michael@0: unsigned int labelLen, michael@0: const unsigned char * seed, michael@0: unsigned int seedLen, michael@0: unsigned char * output, michael@0: unsigned int * outputLen, michael@0: unsigned int maxOutputLen, michael@0: const unsigned char * input, michael@0: unsigned int inputLen); michael@0: michael@0: extern SECStatus michael@0: RSA_DecryptOAEP(RSAPrivateKey * key, michael@0: HASH_HashType hashAlg, michael@0: HASH_HashType maskHashAlg, michael@0: const unsigned char * label, michael@0: unsigned int labelLen, michael@0: unsigned char * output, michael@0: unsigned int * outputLen, michael@0: unsigned int maxOutputLen, michael@0: const unsigned char * input, michael@0: unsigned int inputLen); michael@0: michael@0: /******************************************************************** michael@0: ** RSAES-PKCS1-v1_5 encryption/decryption, as defined in RFC 3447, Section 7.2. michael@0: */ michael@0: extern SECStatus michael@0: RSA_EncryptBlock(RSAPublicKey * key, michael@0: unsigned char * output, michael@0: unsigned int * outputLen, michael@0: unsigned int maxOutputLen, michael@0: const unsigned char * input, michael@0: unsigned int inputLen); michael@0: michael@0: extern SECStatus michael@0: RSA_DecryptBlock(RSAPrivateKey * key, michael@0: unsigned char * output, michael@0: unsigned int * outputLen, michael@0: unsigned int maxOutputLen, michael@0: const unsigned char * input, michael@0: unsigned int inputLen); michael@0: michael@0: /******************************************************************** michael@0: ** RSASSA-PSS signing/verifying, as defined in RFC 3447, Section 8.1. michael@0: ** michael@0: ** Note: Only MGF1 is supported as the mask generation function. It will be michael@0: ** used with maskHashAlg as the inner hash function. michael@0: ** michael@0: ** Unless performing Known Answer Tests, "salt" should be NULL, indicating that michael@0: ** freebl should generate a random value. michael@0: */ michael@0: extern SECStatus michael@0: RSA_SignPSS(RSAPrivateKey * key, michael@0: HASH_HashType hashAlg, michael@0: HASH_HashType maskHashAlg, michael@0: const unsigned char * salt, michael@0: unsigned int saltLen, michael@0: unsigned char * output, michael@0: unsigned int * outputLen, michael@0: unsigned int maxOutputLen, michael@0: const unsigned char * input, michael@0: unsigned int inputLen); michael@0: michael@0: extern SECStatus michael@0: RSA_CheckSignPSS(RSAPublicKey * key, michael@0: HASH_HashType hashAlg, michael@0: HASH_HashType maskHashAlg, michael@0: unsigned int saltLen, michael@0: const unsigned char * sig, michael@0: unsigned int sigLen, michael@0: const unsigned char * hash, michael@0: unsigned int hashLen); michael@0: michael@0: /******************************************************************** michael@0: ** RSASSA-PKCS1-v1_5 signing/verifying, as defined in RFC 3447, Section 8.2. michael@0: ** michael@0: ** These functions expect as input to be the raw value to be signed. For most michael@0: ** cases using PKCS1-v1_5, this should be the value of T, the DER-encoded michael@0: ** DigestInfo structure defined in Section 9.2, Step 2. michael@0: ** Note: This can also be used for signatures that use PKCS1-v1_5 padding, such michael@0: ** as the signatures used in SSL/TLS, which sign a raw hash. michael@0: */ michael@0: extern SECStatus michael@0: RSA_Sign(RSAPrivateKey * key, michael@0: unsigned char * output, michael@0: unsigned int * outputLen, michael@0: unsigned int maxOutputLen, michael@0: const unsigned char * data, michael@0: unsigned int dataLen); michael@0: michael@0: extern SECStatus michael@0: RSA_CheckSign(RSAPublicKey * key, michael@0: const unsigned char * sig, michael@0: unsigned int sigLen, michael@0: const unsigned char * data, michael@0: unsigned int dataLen); michael@0: michael@0: extern SECStatus michael@0: RSA_CheckSignRecover(RSAPublicKey * key, michael@0: unsigned char * output, michael@0: unsigned int * outputLen, michael@0: unsigned int maxOutputLen, michael@0: const unsigned char * sig, michael@0: unsigned int sigLen); michael@0: michael@0: /******************************************************************** michael@0: ** DSA signing algorithm michael@0: */ michael@0: michael@0: /* Generate a new random value within the interval [2, q-1]. michael@0: */ michael@0: extern SECStatus DSA_NewRandom(PLArenaPool * arena, const SECItem * q, michael@0: SECItem * random); michael@0: michael@0: /* michael@0: ** Generate and return a new DSA public and private key pair, michael@0: ** both of which are encoded into a single DSAPrivateKey struct. michael@0: ** "params" is a pointer to the PQG parameters for the domain michael@0: ** Uses a random seed. michael@0: */ michael@0: extern SECStatus DSA_NewKey(const PQGParams * params, michael@0: DSAPrivateKey ** privKey); michael@0: michael@0: /* signature is caller-supplied buffer of at least 20 bytes. michael@0: ** On input, signature->len == size of buffer to hold signature. michael@0: ** digest->len == size of digest. michael@0: ** On output, signature->len == size of signature in buffer. michael@0: ** Uses a random seed. michael@0: */ michael@0: extern SECStatus DSA_SignDigest(DSAPrivateKey * key, michael@0: SECItem * signature, michael@0: const SECItem * digest); michael@0: michael@0: /* signature is caller-supplied buffer of at least 20 bytes. michael@0: ** On input, signature->len == size of buffer to hold signature. michael@0: ** digest->len == size of digest. michael@0: */ michael@0: extern SECStatus DSA_VerifyDigest(DSAPublicKey * key, michael@0: const SECItem * signature, michael@0: const SECItem * digest); michael@0: michael@0: /* For FIPS compliance testing. Seed must be exactly 20 bytes long */ michael@0: extern SECStatus DSA_NewKeyFromSeed(const PQGParams *params, michael@0: const unsigned char * seed, michael@0: DSAPrivateKey **privKey); michael@0: michael@0: /* For FIPS compliance testing. Seed must be exactly 20 bytes. */ michael@0: extern SECStatus DSA_SignDigestWithSeed(DSAPrivateKey * key, michael@0: SECItem * signature, michael@0: const SECItem * digest, michael@0: const unsigned char * seed); michael@0: michael@0: /****************************************************** michael@0: ** Diffie Helman key exchange algorithm michael@0: */ michael@0: michael@0: /* Generates parameters for Diffie-Helman key generation. michael@0: ** primeLen is the length in bytes of prime P to be generated. michael@0: */ michael@0: extern SECStatus DH_GenParam(int primeLen, DHParams ** params); michael@0: michael@0: /* Generates a public and private key, both of which are encoded in a single michael@0: ** DHPrivateKey struct. Params is input, privKey are output. michael@0: ** This is Phase 1 of Diffie Hellman. michael@0: */ michael@0: extern SECStatus DH_NewKey(DHParams * params, michael@0: DHPrivateKey ** privKey); michael@0: michael@0: /* michael@0: ** DH_Derive does the Diffie-Hellman phase 2 calculation, using the michael@0: ** other party's publicValue, and the prime and our privateValue. michael@0: ** maxOutBytes is the requested length of the generated secret in bytes. michael@0: ** A zero value means produce a value of any length up to the size of michael@0: ** the prime. If successful, derivedSecret->data is set michael@0: ** to the address of the newly allocated buffer containing the derived michael@0: ** secret, and derivedSecret->len is the size of the secret produced. michael@0: ** The size of the secret produced will depend on the value of outBytes. michael@0: ** If outBytes is 0, the key length will be all the significant bytes of michael@0: ** the derived secret (leading zeros are dropped). This length could be less michael@0: ** than the length of the prime. If outBytes is nonzero, the length of the michael@0: ** produced key will be outBytes long. If the key is truncated, the most michael@0: ** significant bytes are truncated. If it is expanded, zero bytes are added michael@0: ** at the beginning. michael@0: ** It is the caller's responsibility to free the allocated buffer michael@0: ** containing the derived secret. michael@0: */ michael@0: extern SECStatus DH_Derive(SECItem * publicValue, michael@0: SECItem * prime, michael@0: SECItem * privateValue, michael@0: SECItem * derivedSecret, michael@0: unsigned int outBytes); michael@0: michael@0: /* michael@0: ** KEA_CalcKey returns octet string with the private key for a dual michael@0: ** Diffie-Helman key generation as specified for government key exchange. michael@0: */ michael@0: extern SECStatus KEA_Derive(SECItem *prime, michael@0: SECItem *public1, michael@0: SECItem *public2, michael@0: SECItem *private1, michael@0: SECItem *private2, michael@0: SECItem *derivedSecret); michael@0: michael@0: /* michael@0: * verify that a KEA or DSA public key is a valid key for this prime and michael@0: * subprime domain. michael@0: */ michael@0: extern PRBool KEA_Verify(SECItem *Y, SECItem *prime, SECItem *subPrime); michael@0: michael@0: /**************************************** michael@0: * J-PAKE key transport michael@0: */ michael@0: michael@0: /* Given gx == g^x, create a Schnorr zero-knowledge proof for the value x michael@0: * using the specified hash algorithm and signer ID. The signature is michael@0: * returned in the values gv and r. testRandom must be NULL for a PRNG michael@0: * generated random committment to be used in the sigature. When testRandom michael@0: * is non-NULL, that value must contain a value in the subgroup q; that michael@0: * value will be used instead of a PRNG-generated committment in order to michael@0: * facilitate known-answer tests. michael@0: * michael@0: * If gxIn is non-NULL then it must contain a pre-computed value of g^x that michael@0: * will be used by the function; in this case, the gxOut parameter must be NULL. michael@0: * If the gxIn parameter is NULL then gxOut must be non-NULL; in this case michael@0: * gxOut will contain the value g^x on output. michael@0: * michael@0: * gx (if not supplied by the caller), gv, and r will be allocated in the arena. michael@0: * The arena is *not* optional so do not pass NULL for the arena parameter. michael@0: * The arena should be zeroed when it is freed. michael@0: */ michael@0: SECStatus michael@0: JPAKE_Sign(PLArenaPool * arena, const PQGParams * pqg, HASH_HashType hashType, michael@0: const SECItem * signerID, const SECItem * x, michael@0: const SECItem * testRandom, const SECItem * gxIn, SECItem * gxOut, michael@0: SECItem * gv, SECItem * r); michael@0: michael@0: /* Given gx == g^x, verify the Schnorr zero-knowledge proof (gv, r) for the michael@0: * value x using the specified hash algorithm and signer ID. michael@0: * michael@0: * The arena is *not* optional so do not pass NULL for the arena parameter. michael@0: */ michael@0: SECStatus michael@0: JPAKE_Verify(PLArenaPool * arena, const PQGParams * pqg, michael@0: HASH_HashType hashType, const SECItem * signerID, michael@0: const SECItem * peerID, const SECItem * gx, michael@0: const SECItem * gv, const SECItem * r); michael@0: michael@0: /* Call before round 2 with x2, s, and x2s all non-NULL. This will calculate michael@0: * base = g^(x1+x3+x4) (mod p) and x2s = x2*s (mod q). The values to send in michael@0: * round 2 (A and the proof of knowledge of x2s) can then be calculated with michael@0: * JPAKE_Sign using pqg->base = base and x = x2s. michael@0: * michael@0: * Call after round 2 with x2, s, and x2s all NULL, and passing (gx1, gx2, gx3) michael@0: * instead of (gx1, gx3, gx4). This will calculate base = g^(x1+x2+x3). Then call michael@0: * JPAKE_Verify with pqg->base = base and then JPAKE_Final. michael@0: * michael@0: * base and x2s will be allocated in the arena. The arena is *not* optional so michael@0: * do not pass NULL for the arena parameter. The arena should be zeroed when it michael@0: * is freed. michael@0: */ michael@0: SECStatus michael@0: JPAKE_Round2(PLArenaPool * arena, const SECItem * p, const SECItem *q, michael@0: const SECItem * gx1, const SECItem * gx3, const SECItem * gx4, michael@0: SECItem * base, const SECItem * x2, const SECItem * s, SECItem * x2s); michael@0: michael@0: /* K = (B/g^(x2*x4*s))^x2 (mod p) michael@0: * michael@0: * K will be allocated in the arena. The arena is *not* optional so do not pass michael@0: * NULL for the arena parameter. The arena should be zeroed when it is freed. michael@0: */ michael@0: SECStatus michael@0: JPAKE_Final(PLArenaPool * arena, const SECItem * p, const SECItem *q, michael@0: const SECItem * x2, const SECItem * gx4, const SECItem * x2s, michael@0: const SECItem * B, SECItem * K); michael@0: michael@0: /****************************************************** michael@0: ** Elliptic Curve algorithms michael@0: */ michael@0: michael@0: /* Generates a public and private key, both of which are encoded michael@0: ** in a single ECPrivateKey struct. Params is input, privKey are michael@0: ** output. michael@0: */ michael@0: extern SECStatus EC_NewKey(ECParams * params, michael@0: ECPrivateKey ** privKey); michael@0: michael@0: extern SECStatus EC_NewKeyFromSeed(ECParams * params, michael@0: ECPrivateKey ** privKey, michael@0: const unsigned char* seed, michael@0: int seedlen); michael@0: michael@0: /* Validates an EC public key as described in Section 5.2.2 of michael@0: * X9.62. Such validation prevents against small subgroup attacks michael@0: * when the ECDH primitive is used with the cofactor. michael@0: */ michael@0: extern SECStatus EC_ValidatePublicKey(ECParams * params, michael@0: SECItem * publicValue); michael@0: michael@0: /* michael@0: ** ECDH_Derive performs a scalar point multiplication of a point michael@0: ** representing a (peer's) public key and a large integer representing michael@0: ** a private key (its own). Both keys must use the same elliptic curve michael@0: ** parameters. If the withCofactor parameter is true, the michael@0: ** multiplication also uses the cofactor associated with the curve michael@0: ** parameters. The output of this scheme is the x-coordinate of the michael@0: ** resulting point. If successful, derivedSecret->data is set to the michael@0: ** address of the newly allocated buffer containing the derived michael@0: ** secret, and derivedSecret->len is the size of the secret michael@0: ** produced. It is the caller's responsibility to free the allocated michael@0: ** buffer containing the derived secret. michael@0: */ michael@0: extern SECStatus ECDH_Derive(SECItem * publicValue, michael@0: ECParams * params, michael@0: SECItem * privateValue, michael@0: PRBool withCofactor, michael@0: SECItem * derivedSecret); michael@0: michael@0: /* On input, signature->len == size of buffer to hold signature. michael@0: ** digest->len == size of digest. michael@0: ** On output, signature->len == size of signature in buffer. michael@0: ** Uses a random seed. michael@0: */ michael@0: extern SECStatus ECDSA_SignDigest(ECPrivateKey *key, michael@0: SECItem *signature, michael@0: const SECItem *digest); michael@0: michael@0: /* On input, signature->len == size of buffer to hold signature. michael@0: ** digest->len == size of digest. michael@0: */ michael@0: extern SECStatus ECDSA_VerifyDigest(ECPublicKey *key, michael@0: const SECItem *signature, michael@0: const SECItem *digest); michael@0: michael@0: /* Uses the provided seed. */ michael@0: extern SECStatus ECDSA_SignDigestWithSeed(ECPrivateKey *key, michael@0: SECItem *signature, michael@0: const SECItem *digest, michael@0: const unsigned char *seed, michael@0: const int seedlen); michael@0: michael@0: /******************************************/ michael@0: /* michael@0: ** RC4 symmetric stream cypher michael@0: */ michael@0: michael@0: /* michael@0: ** Create a new RC4 context suitable for RC4 encryption/decryption. michael@0: ** "key" raw key data michael@0: ** "len" the number of bytes of key data michael@0: */ michael@0: extern RC4Context *RC4_CreateContext(const unsigned char *key, int len); michael@0: michael@0: extern RC4Context *RC4_AllocateContext(void); michael@0: extern SECStatus RC4_InitContext(RC4Context *cx, michael@0: const unsigned char *key, michael@0: unsigned int keylen, michael@0: const unsigned char *, michael@0: int, michael@0: unsigned int , michael@0: unsigned int ); michael@0: michael@0: /* michael@0: ** Destroy an RC4 encryption/decryption context. michael@0: ** "cx" the context michael@0: ** "freeit" if PR_TRUE then free the object as well as its sub-objects michael@0: */ michael@0: extern void RC4_DestroyContext(RC4Context *cx, PRBool freeit); michael@0: michael@0: /* michael@0: ** Perform RC4 encryption. michael@0: ** "cx" the context michael@0: ** "output" the output buffer to store the encrypted data. michael@0: ** "outputLen" how much data is stored in "output". Set by the routine michael@0: ** after some data is stored in output. michael@0: ** "maxOutputLen" the maximum amount of data that can ever be michael@0: ** stored in "output" michael@0: ** "input" the input data michael@0: ** "inputLen" the amount of input data michael@0: */ michael@0: extern SECStatus RC4_Encrypt(RC4Context *cx, unsigned char *output, michael@0: unsigned int *outputLen, unsigned int maxOutputLen, michael@0: const unsigned char *input, unsigned int inputLen); michael@0: michael@0: /* michael@0: ** Perform RC4 decryption. michael@0: ** "cx" the context michael@0: ** "output" the output buffer to store the decrypted data. michael@0: ** "outputLen" how much data is stored in "output". Set by the routine michael@0: ** after some data is stored in output. michael@0: ** "maxOutputLen" the maximum amount of data that can ever be michael@0: ** stored in "output" michael@0: ** "input" the input data michael@0: ** "inputLen" the amount of input data michael@0: */ michael@0: extern SECStatus RC4_Decrypt(RC4Context *cx, unsigned char *output, michael@0: unsigned int *outputLen, unsigned int maxOutputLen, michael@0: const unsigned char *input, unsigned int inputLen); michael@0: michael@0: /******************************************/ michael@0: /* michael@0: ** RC2 symmetric block cypher michael@0: */ michael@0: michael@0: /* michael@0: ** Create a new RC2 context suitable for RC2 encryption/decryption. michael@0: ** "key" raw key data michael@0: ** "len" the number of bytes of key data michael@0: ** "iv" is the CBC initialization vector (if mode is NSS_RC2_CBC) michael@0: ** "mode" one of NSS_RC2 or NSS_RC2_CBC michael@0: ** "effectiveKeyLen" is the effective key length (as specified in michael@0: ** RFC 2268) in bytes (not bits). michael@0: ** michael@0: ** When mode is set to NSS_RC2_CBC the RC2 cipher is run in "cipher block michael@0: ** chaining" mode. michael@0: */ michael@0: extern RC2Context *RC2_CreateContext(const unsigned char *key, unsigned int len, michael@0: const unsigned char *iv, int mode, michael@0: unsigned effectiveKeyLen); michael@0: extern RC2Context *RC2_AllocateContext(void); michael@0: extern SECStatus RC2_InitContext(RC2Context *cx, michael@0: const unsigned char *key, michael@0: unsigned int keylen, michael@0: const unsigned char *iv, michael@0: int mode, michael@0: unsigned int effectiveKeyLen, michael@0: unsigned int ); michael@0: michael@0: /* michael@0: ** Destroy an RC2 encryption/decryption context. michael@0: ** "cx" the context michael@0: ** "freeit" if PR_TRUE then free the object as well as its sub-objects michael@0: */ michael@0: extern void RC2_DestroyContext(RC2Context *cx, PRBool freeit); michael@0: michael@0: /* michael@0: ** Perform RC2 encryption. michael@0: ** "cx" the context michael@0: ** "output" the output buffer to store the encrypted data. michael@0: ** "outputLen" how much data is stored in "output". Set by the routine michael@0: ** after some data is stored in output. michael@0: ** "maxOutputLen" the maximum amount of data that can ever be michael@0: ** stored in "output" michael@0: ** "input" the input data michael@0: ** "inputLen" the amount of input data michael@0: */ michael@0: extern SECStatus RC2_Encrypt(RC2Context *cx, unsigned char *output, michael@0: unsigned int *outputLen, unsigned int maxOutputLen, michael@0: const unsigned char *input, unsigned int inputLen); michael@0: michael@0: /* michael@0: ** Perform RC2 decryption. michael@0: ** "cx" the context michael@0: ** "output" the output buffer to store the decrypted data. michael@0: ** "outputLen" how much data is stored in "output". Set by the routine michael@0: ** after some data is stored in output. michael@0: ** "maxOutputLen" the maximum amount of data that can ever be michael@0: ** stored in "output" michael@0: ** "input" the input data michael@0: ** "inputLen" the amount of input data michael@0: */ michael@0: extern SECStatus RC2_Decrypt(RC2Context *cx, unsigned char *output, michael@0: unsigned int *outputLen, unsigned int maxOutputLen, michael@0: const unsigned char *input, unsigned int inputLen); michael@0: michael@0: /******************************************/ michael@0: /* michael@0: ** RC5 symmetric block cypher -- 64-bit block size michael@0: */ michael@0: michael@0: /* michael@0: ** Create a new RC5 context suitable for RC5 encryption/decryption. michael@0: ** "key" raw key data michael@0: ** "len" the number of bytes of key data michael@0: ** "iv" is the CBC initialization vector (if mode is NSS_RC5_CBC) michael@0: ** "mode" one of NSS_RC5 or NSS_RC5_CBC michael@0: ** michael@0: ** When mode is set to NSS_RC5_CBC the RC5 cipher is run in "cipher block michael@0: ** chaining" mode. michael@0: */ michael@0: extern RC5Context *RC5_CreateContext(const SECItem *key, unsigned int rounds, michael@0: unsigned int wordSize, const unsigned char *iv, int mode); michael@0: extern RC5Context *RC5_AllocateContext(void); michael@0: extern SECStatus RC5_InitContext(RC5Context *cx, michael@0: const unsigned char *key, michael@0: unsigned int keylen, michael@0: const unsigned char *iv, michael@0: int mode, michael@0: unsigned int rounds, michael@0: unsigned int wordSize); michael@0: michael@0: /* michael@0: ** Destroy an RC5 encryption/decryption context. michael@0: ** "cx" the context michael@0: ** "freeit" if PR_TRUE then free the object as well as its sub-objects michael@0: */ michael@0: extern void RC5_DestroyContext(RC5Context *cx, PRBool freeit); michael@0: michael@0: /* michael@0: ** Perform RC5 encryption. michael@0: ** "cx" the context michael@0: ** "output" the output buffer to store the encrypted data. michael@0: ** "outputLen" how much data is stored in "output". Set by the routine michael@0: ** after some data is stored in output. michael@0: ** "maxOutputLen" the maximum amount of data that can ever be michael@0: ** stored in "output" michael@0: ** "input" the input data michael@0: ** "inputLen" the amount of input data michael@0: */ michael@0: extern SECStatus RC5_Encrypt(RC5Context *cx, unsigned char *output, michael@0: unsigned int *outputLen, unsigned int maxOutputLen, michael@0: const unsigned char *input, unsigned int inputLen); michael@0: michael@0: /* michael@0: ** Perform RC5 decryption. michael@0: ** "cx" the context michael@0: ** "output" the output buffer to store the decrypted data. michael@0: ** "outputLen" how much data is stored in "output". Set by the routine michael@0: ** after some data is stored in output. michael@0: ** "maxOutputLen" the maximum amount of data that can ever be michael@0: ** stored in "output" michael@0: ** "input" the input data michael@0: ** "inputLen" the amount of input data michael@0: */ michael@0: michael@0: extern SECStatus RC5_Decrypt(RC5Context *cx, unsigned char *output, michael@0: unsigned int *outputLen, unsigned int maxOutputLen, michael@0: const unsigned char *input, unsigned int inputLen); michael@0: michael@0: michael@0: michael@0: /******************************************/ michael@0: /* michael@0: ** DES symmetric block cypher michael@0: */ michael@0: michael@0: /* michael@0: ** Create a new DES context suitable for DES encryption/decryption. michael@0: ** "key" raw key data michael@0: ** "len" the number of bytes of key data michael@0: ** "iv" is the CBC initialization vector (if mode is NSS_DES_CBC or michael@0: ** mode is DES_EDE3_CBC) michael@0: ** "mode" one of NSS_DES, NSS_DES_CBC, NSS_DES_EDE3 or NSS_DES_EDE3_CBC michael@0: ** "encrypt" is PR_TRUE if the context will be used for encryption michael@0: ** michael@0: ** When mode is set to NSS_DES_CBC or NSS_DES_EDE3_CBC then the DES michael@0: ** cipher is run in "cipher block chaining" mode. michael@0: */ michael@0: extern DESContext *DES_CreateContext(const unsigned char *key, michael@0: const unsigned char *iv, michael@0: int mode, PRBool encrypt); michael@0: extern DESContext *DES_AllocateContext(void); michael@0: extern SECStatus DES_InitContext(DESContext *cx, michael@0: const unsigned char *key, michael@0: unsigned int keylen, michael@0: const unsigned char *iv, michael@0: int mode, michael@0: unsigned int encrypt, michael@0: unsigned int ); michael@0: michael@0: /* michael@0: ** Destroy an DES encryption/decryption context. michael@0: ** "cx" the context michael@0: ** "freeit" if PR_TRUE then free the object as well as its sub-objects michael@0: */ michael@0: extern void DES_DestroyContext(DESContext *cx, PRBool freeit); michael@0: michael@0: /* michael@0: ** Perform DES encryption. michael@0: ** "cx" the context michael@0: ** "output" the output buffer to store the encrypted data. michael@0: ** "outputLen" how much data is stored in "output". Set by the routine michael@0: ** after some data is stored in output. michael@0: ** "maxOutputLen" the maximum amount of data that can ever be michael@0: ** stored in "output" michael@0: ** "input" the input data michael@0: ** "inputLen" the amount of input data michael@0: ** michael@0: ** NOTE: the inputLen must be a multiple of DES_KEY_LENGTH michael@0: */ michael@0: extern SECStatus DES_Encrypt(DESContext *cx, unsigned char *output, michael@0: unsigned int *outputLen, unsigned int maxOutputLen, michael@0: const unsigned char *input, unsigned int inputLen); michael@0: michael@0: /* michael@0: ** Perform DES decryption. michael@0: ** "cx" the context michael@0: ** "output" the output buffer to store the decrypted data. michael@0: ** "outputLen" how much data is stored in "output". Set by the routine michael@0: ** after some data is stored in output. michael@0: ** "maxOutputLen" the maximum amount of data that can ever be michael@0: ** stored in "output" michael@0: ** "input" the input data michael@0: ** "inputLen" the amount of input data michael@0: ** michael@0: ** NOTE: the inputLen must be a multiple of DES_KEY_LENGTH michael@0: */ michael@0: extern SECStatus DES_Decrypt(DESContext *cx, unsigned char *output, michael@0: unsigned int *outputLen, unsigned int maxOutputLen, michael@0: const unsigned char *input, unsigned int inputLen); michael@0: michael@0: /******************************************/ michael@0: /* michael@0: ** SEED symmetric block cypher michael@0: */ michael@0: extern SEEDContext * michael@0: SEED_CreateContext(const unsigned char *key, const unsigned char *iv, michael@0: int mode, PRBool encrypt); michael@0: extern SEEDContext *SEED_AllocateContext(void); michael@0: extern SECStatus SEED_InitContext(SEEDContext *cx, michael@0: const unsigned char *key, michael@0: unsigned int keylen, michael@0: const unsigned char *iv, michael@0: int mode, unsigned int encrypt, michael@0: unsigned int ); michael@0: extern void SEED_DestroyContext(SEEDContext *cx, PRBool freeit); michael@0: extern SECStatus michael@0: SEED_Encrypt(SEEDContext *cx, unsigned char *output, michael@0: unsigned int *outputLen, unsigned int maxOutputLen, michael@0: const unsigned char *input, unsigned int inputLen); michael@0: extern SECStatus michael@0: SEED_Decrypt(SEEDContext *cx, unsigned char *output, michael@0: unsigned int *outputLen, unsigned int maxOutputLen, michael@0: const unsigned char *input, unsigned int inputLen); michael@0: michael@0: /******************************************/ michael@0: /* michael@0: ** AES symmetric block cypher (Rijndael) michael@0: */ michael@0: michael@0: /* michael@0: ** Create a new AES context suitable for AES encryption/decryption. michael@0: ** "key" raw key data michael@0: ** "keylen" the number of bytes of key data (16, 24, or 32) michael@0: ** "blocklen" is the blocksize to use (16, 24, or 32) michael@0: ** XXX currently only blocksize==16 has been tested! michael@0: */ michael@0: extern AESContext * michael@0: AES_CreateContext(const unsigned char *key, const unsigned char *iv, michael@0: int mode, int encrypt, michael@0: unsigned int keylen, unsigned int blocklen); michael@0: extern AESContext *AES_AllocateContext(void); michael@0: extern SECStatus AES_InitContext(AESContext *cx, michael@0: const unsigned char *key, michael@0: unsigned int keylen, michael@0: const unsigned char *iv, michael@0: int mode, michael@0: unsigned int encrypt, michael@0: unsigned int blocklen); michael@0: michael@0: /* michael@0: ** Destroy a AES encryption/decryption context. michael@0: ** "cx" the context michael@0: ** "freeit" if PR_TRUE then free the object as well as its sub-objects michael@0: */ michael@0: extern void michael@0: AES_DestroyContext(AESContext *cx, PRBool freeit); michael@0: michael@0: /* michael@0: ** Perform AES encryption. michael@0: ** "cx" the context michael@0: ** "output" the output buffer to store the encrypted data. michael@0: ** "outputLen" how much data is stored in "output". Set by the routine michael@0: ** after some data is stored in output. michael@0: ** "maxOutputLen" the maximum amount of data that can ever be michael@0: ** stored in "output" michael@0: ** "input" the input data michael@0: ** "inputLen" the amount of input data michael@0: */ michael@0: extern SECStatus michael@0: AES_Encrypt(AESContext *cx, unsigned char *output, michael@0: unsigned int *outputLen, unsigned int maxOutputLen, michael@0: const unsigned char *input, unsigned int inputLen); michael@0: michael@0: /* michael@0: ** Perform AES decryption. michael@0: ** "cx" the context michael@0: ** "output" the output buffer to store the decrypted data. michael@0: ** "outputLen" how much data is stored in "output". Set by the routine michael@0: ** after some data is stored in output. michael@0: ** "maxOutputLen" the maximum amount of data that can ever be michael@0: ** stored in "output" michael@0: ** "input" the input data michael@0: ** "inputLen" the amount of input data michael@0: */ michael@0: extern SECStatus michael@0: AES_Decrypt(AESContext *cx, unsigned char *output, michael@0: unsigned int *outputLen, unsigned int maxOutputLen, michael@0: const unsigned char *input, unsigned int inputLen); michael@0: michael@0: /******************************************/ michael@0: /* michael@0: ** AES key wrap algorithm, RFC 3394 michael@0: */ michael@0: michael@0: /* michael@0: ** Create a new AES context suitable for AES encryption/decryption. michael@0: ** "key" raw key data michael@0: ** "iv" The 8 byte "initial value" michael@0: ** "encrypt", a boolean, true for key wrapping, false for unwrapping. michael@0: ** "keylen" the number of bytes of key data (16, 24, or 32) michael@0: */ michael@0: extern AESKeyWrapContext * michael@0: AESKeyWrap_CreateContext(const unsigned char *key, const unsigned char *iv, michael@0: int encrypt, unsigned int keylen); michael@0: extern AESKeyWrapContext * AESKeyWrap_AllocateContext(void); michael@0: extern SECStatus michael@0: AESKeyWrap_InitContext(AESKeyWrapContext *cx, michael@0: const unsigned char *key, michael@0: unsigned int keylen, michael@0: const unsigned char *iv, michael@0: int , michael@0: unsigned int encrypt, michael@0: unsigned int ); michael@0: michael@0: /* michael@0: ** Destroy a AES KeyWrap context. michael@0: ** "cx" the context michael@0: ** "freeit" if PR_TRUE then free the object as well as its sub-objects michael@0: */ michael@0: extern void michael@0: AESKeyWrap_DestroyContext(AESKeyWrapContext *cx, PRBool freeit); michael@0: michael@0: /* michael@0: ** Perform AES key wrap. michael@0: ** "cx" the context michael@0: ** "output" the output buffer to store the encrypted data. michael@0: ** "outputLen" how much data is stored in "output". Set by the routine michael@0: ** after some data is stored in output. michael@0: ** "maxOutputLen" the maximum amount of data that can ever be michael@0: ** stored in "output" michael@0: ** "input" the input data michael@0: ** "inputLen" the amount of input data michael@0: */ michael@0: extern SECStatus michael@0: AESKeyWrap_Encrypt(AESKeyWrapContext *cx, unsigned char *output, michael@0: unsigned int *outputLen, unsigned int maxOutputLen, michael@0: const unsigned char *input, unsigned int inputLen); michael@0: michael@0: /* michael@0: ** Perform AES key unwrap. michael@0: ** "cx" the context michael@0: ** "output" the output buffer to store the decrypted data. michael@0: ** "outputLen" how much data is stored in "output". Set by the routine michael@0: ** after some data is stored in output. michael@0: ** "maxOutputLen" the maximum amount of data that can ever be michael@0: ** stored in "output" michael@0: ** "input" the input data michael@0: ** "inputLen" the amount of input data michael@0: */ michael@0: extern SECStatus michael@0: AESKeyWrap_Decrypt(AESKeyWrapContext *cx, unsigned char *output, michael@0: unsigned int *outputLen, unsigned int maxOutputLen, michael@0: const unsigned char *input, unsigned int inputLen); michael@0: michael@0: /******************************************/ michael@0: /* michael@0: ** Camellia symmetric block cypher michael@0: */ michael@0: michael@0: /* michael@0: ** Create a new Camellia context suitable for Camellia encryption/decryption. michael@0: ** "key" raw key data michael@0: ** "keylen" the number of bytes of key data (16, 24, or 32) michael@0: */ michael@0: extern CamelliaContext * michael@0: Camellia_CreateContext(const unsigned char *key, const unsigned char *iv, michael@0: int mode, int encrypt, unsigned int keylen); michael@0: michael@0: extern CamelliaContext *Camellia_AllocateContext(void); michael@0: extern SECStatus Camellia_InitContext(CamelliaContext *cx, michael@0: const unsigned char *key, michael@0: unsigned int keylen, michael@0: const unsigned char *iv, michael@0: int mode, michael@0: unsigned int encrypt, michael@0: unsigned int unused); michael@0: /* michael@0: ** Destroy a Camellia encryption/decryption context. michael@0: ** "cx" the context michael@0: ** "freeit" if PR_TRUE then free the object as well as its sub-objects michael@0: */ michael@0: extern void michael@0: Camellia_DestroyContext(CamelliaContext *cx, PRBool freeit); michael@0: michael@0: /* michael@0: ** Perform Camellia encryption. michael@0: ** "cx" the context michael@0: ** "output" the output buffer to store the encrypted data. michael@0: ** "outputLen" how much data is stored in "output". Set by the routine michael@0: ** after some data is stored in output. michael@0: ** "maxOutputLen" the maximum amount of data that can ever be michael@0: ** stored in "output" michael@0: ** "input" the input data michael@0: ** "inputLen" the amount of input data michael@0: */ michael@0: extern SECStatus michael@0: Camellia_Encrypt(CamelliaContext *cx, unsigned char *output, michael@0: unsigned int *outputLen, unsigned int maxOutputLen, michael@0: const unsigned char *input, unsigned int inputLen); michael@0: michael@0: /* michael@0: ** Perform Camellia decryption. michael@0: ** "cx" the context michael@0: ** "output" the output buffer to store the decrypted data. michael@0: ** "outputLen" how much data is stored in "output". Set by the routine michael@0: ** after some data is stored in output. michael@0: ** "maxOutputLen" the maximum amount of data that can ever be michael@0: ** stored in "output" michael@0: ** "input" the input data michael@0: ** "inputLen" the amount of input data michael@0: */ michael@0: extern SECStatus michael@0: Camellia_Decrypt(CamelliaContext *cx, unsigned char *output, michael@0: unsigned int *outputLen, unsigned int maxOutputLen, michael@0: const unsigned char *input, unsigned int inputLen); michael@0: michael@0: michael@0: /******************************************/ michael@0: /* michael@0: ** MD5 secure hash function michael@0: */ michael@0: michael@0: /* michael@0: ** Hash a null terminated string "src" into "dest" using MD5 michael@0: */ michael@0: extern SECStatus MD5_Hash(unsigned char *dest, const char *src); michael@0: michael@0: /* michael@0: ** Hash a non-null terminated string "src" into "dest" using MD5 michael@0: */ michael@0: extern SECStatus MD5_HashBuf(unsigned char *dest, const unsigned char *src, michael@0: PRUint32 src_length); michael@0: michael@0: /* michael@0: ** Create a new MD5 context michael@0: */ michael@0: extern MD5Context *MD5_NewContext(void); michael@0: michael@0: michael@0: /* michael@0: ** Destroy an MD5 secure hash context. michael@0: ** "cx" the context michael@0: ** "freeit" if PR_TRUE then free the object as well as its sub-objects michael@0: */ michael@0: extern void MD5_DestroyContext(MD5Context *cx, PRBool freeit); michael@0: michael@0: /* michael@0: ** Reset an MD5 context, preparing it for a fresh round of hashing michael@0: */ michael@0: extern void MD5_Begin(MD5Context *cx); michael@0: michael@0: /* michael@0: ** Update the MD5 hash function with more data. michael@0: ** "cx" the context michael@0: ** "input" the data to hash michael@0: ** "inputLen" the amount of data to hash michael@0: */ michael@0: extern void MD5_Update(MD5Context *cx, michael@0: const unsigned char *input, unsigned int inputLen); michael@0: michael@0: /* michael@0: ** Finish the MD5 hash function. Produce the digested results in "digest" michael@0: ** "cx" the context michael@0: ** "digest" where the 16 bytes of digest data are stored michael@0: ** "digestLen" where the digest length (16) is stored michael@0: ** "maxDigestLen" the maximum amount of data that can ever be michael@0: ** stored in "digest" michael@0: */ michael@0: extern void MD5_End(MD5Context *cx, unsigned char *digest, michael@0: unsigned int *digestLen, unsigned int maxDigestLen); michael@0: michael@0: /* michael@0: ** Export the current state of the MD5 hash without appending the standard michael@0: ** padding and length bytes. Produce the digested results in "digest" michael@0: ** "cx" the context michael@0: ** "digest" where the 16 bytes of digest data are stored michael@0: ** "digestLen" where the digest length (16) is stored (optional) michael@0: ** "maxDigestLen" the maximum amount of data that can ever be michael@0: ** stored in "digest" michael@0: */ michael@0: extern void MD5_EndRaw(MD5Context *cx, unsigned char *digest, michael@0: unsigned int *digestLen, unsigned int maxDigestLen); michael@0: michael@0: /* michael@0: * Return the the size of a buffer needed to flatten the MD5 Context into michael@0: * "cx" the context michael@0: * returns size; michael@0: */ michael@0: extern unsigned int MD5_FlattenSize(MD5Context *cx); michael@0: michael@0: /* michael@0: * Flatten the MD5 Context into a buffer: michael@0: * "cx" the context michael@0: * "space" the buffer to flatten to michael@0: * returns status; michael@0: */ michael@0: extern SECStatus MD5_Flatten(MD5Context *cx,unsigned char *space); michael@0: michael@0: /* michael@0: * Resurrect a flattened context into a MD5 Context michael@0: * "space" the buffer of the flattend buffer michael@0: * "arg" ptr to void used by cryptographic resurrect michael@0: * returns resurected context; michael@0: */ michael@0: extern MD5Context * MD5_Resurrect(unsigned char *space, void *arg); michael@0: extern void MD5_Clone(MD5Context *dest, MD5Context *src); michael@0: michael@0: /* michael@0: ** trace the intermediate state info of the MD5 hash. michael@0: */ michael@0: extern void MD5_TraceState(MD5Context *cx); michael@0: michael@0: michael@0: /******************************************/ michael@0: /* michael@0: ** MD2 secure hash function michael@0: */ michael@0: michael@0: /* michael@0: ** Hash a null terminated string "src" into "dest" using MD2 michael@0: */ michael@0: extern SECStatus MD2_Hash(unsigned char *dest, const char *src); michael@0: michael@0: /* michael@0: ** Create a new MD2 context michael@0: */ michael@0: extern MD2Context *MD2_NewContext(void); michael@0: michael@0: michael@0: /* michael@0: ** Destroy an MD2 secure hash context. michael@0: ** "cx" the context michael@0: ** "freeit" if PR_TRUE then free the object as well as its sub-objects michael@0: */ michael@0: extern void MD2_DestroyContext(MD2Context *cx, PRBool freeit); michael@0: michael@0: /* michael@0: ** Reset an MD2 context, preparing it for a fresh round of hashing michael@0: */ michael@0: extern void MD2_Begin(MD2Context *cx); michael@0: michael@0: /* michael@0: ** Update the MD2 hash function with more data. michael@0: ** "cx" the context michael@0: ** "input" the data to hash michael@0: ** "inputLen" the amount of data to hash michael@0: */ michael@0: extern void MD2_Update(MD2Context *cx, michael@0: const unsigned char *input, unsigned int inputLen); michael@0: michael@0: /* michael@0: ** Finish the MD2 hash function. Produce the digested results in "digest" michael@0: ** "cx" the context michael@0: ** "digest" where the 16 bytes of digest data are stored michael@0: ** "digestLen" where the digest length (16) is stored michael@0: ** "maxDigestLen" the maximum amount of data that can ever be michael@0: ** stored in "digest" michael@0: */ michael@0: extern void MD2_End(MD2Context *cx, unsigned char *digest, michael@0: unsigned int *digestLen, unsigned int maxDigestLen); michael@0: michael@0: /* michael@0: * Return the the size of a buffer needed to flatten the MD2 Context into michael@0: * "cx" the context michael@0: * returns size; michael@0: */ michael@0: extern unsigned int MD2_FlattenSize(MD2Context *cx); michael@0: michael@0: /* michael@0: * Flatten the MD2 Context into a buffer: michael@0: * "cx" the context michael@0: * "space" the buffer to flatten to michael@0: * returns status; michael@0: */ michael@0: extern SECStatus MD2_Flatten(MD2Context *cx,unsigned char *space); michael@0: michael@0: /* michael@0: * Resurrect a flattened context into a MD2 Context michael@0: * "space" the buffer of the flattend buffer michael@0: * "arg" ptr to void used by cryptographic resurrect michael@0: * returns resurected context; michael@0: */ michael@0: extern MD2Context * MD2_Resurrect(unsigned char *space, void *arg); michael@0: extern void MD2_Clone(MD2Context *dest, MD2Context *src); michael@0: michael@0: /******************************************/ michael@0: /* michael@0: ** SHA-1 secure hash function michael@0: */ michael@0: michael@0: /* michael@0: ** Hash a null terminated string "src" into "dest" using SHA-1 michael@0: */ michael@0: extern SECStatus SHA1_Hash(unsigned char *dest, const char *src); michael@0: michael@0: /* michael@0: ** Hash a non-null terminated string "src" into "dest" using SHA-1 michael@0: */ michael@0: extern SECStatus SHA1_HashBuf(unsigned char *dest, const unsigned char *src, michael@0: PRUint32 src_length); michael@0: michael@0: /* michael@0: ** Create a new SHA-1 context michael@0: */ michael@0: extern SHA1Context *SHA1_NewContext(void); michael@0: michael@0: michael@0: /* michael@0: ** Destroy a SHA-1 secure hash context. michael@0: ** "cx" the context michael@0: ** "freeit" if PR_TRUE then free the object as well as its sub-objects michael@0: */ michael@0: extern void SHA1_DestroyContext(SHA1Context *cx, PRBool freeit); michael@0: michael@0: /* michael@0: ** Reset a SHA-1 context, preparing it for a fresh round of hashing michael@0: */ michael@0: extern void SHA1_Begin(SHA1Context *cx); michael@0: michael@0: /* michael@0: ** Update the SHA-1 hash function with more data. michael@0: ** "cx" the context michael@0: ** "input" the data to hash michael@0: ** "inputLen" the amount of data to hash michael@0: */ michael@0: extern void SHA1_Update(SHA1Context *cx, const unsigned char *input, michael@0: unsigned int inputLen); michael@0: michael@0: /* michael@0: ** Finish the SHA-1 hash function. Produce the digested results in "digest" michael@0: ** "cx" the context michael@0: ** "digest" where the 16 bytes of digest data are stored michael@0: ** "digestLen" where the digest length (20) is stored michael@0: ** "maxDigestLen" the maximum amount of data that can ever be michael@0: ** stored in "digest" michael@0: */ michael@0: extern void SHA1_End(SHA1Context *cx, unsigned char *digest, michael@0: unsigned int *digestLen, unsigned int maxDigestLen); michael@0: michael@0: /* michael@0: ** Export the current state of the SHA-1 hash without appending the standard michael@0: ** padding and length bytes. Produce the digested results in "digest" michael@0: ** "cx" the context michael@0: ** "digest" where the 20 bytes of digest data are stored michael@0: ** "digestLen" where the digest length (20) is stored (optional) michael@0: ** "maxDigestLen" the maximum amount of data that can ever be michael@0: ** stored in "digest" michael@0: */ michael@0: extern void SHA1_EndRaw(SHA1Context *cx, unsigned char *digest, michael@0: unsigned int *digestLen, unsigned int maxDigestLen); michael@0: michael@0: /* michael@0: ** trace the intermediate state info of the SHA1 hash. michael@0: */ michael@0: extern void SHA1_TraceState(SHA1Context *cx); michael@0: michael@0: /* michael@0: * Return the the size of a buffer needed to flatten the SHA-1 Context into michael@0: * "cx" the context michael@0: * returns size; michael@0: */ michael@0: extern unsigned int SHA1_FlattenSize(SHA1Context *cx); michael@0: michael@0: /* michael@0: * Flatten the SHA-1 Context into a buffer: michael@0: * "cx" the context michael@0: * "space" the buffer to flatten to michael@0: * returns status; michael@0: */ michael@0: extern SECStatus SHA1_Flatten(SHA1Context *cx,unsigned char *space); michael@0: michael@0: /* michael@0: * Resurrect a flattened context into a SHA-1 Context michael@0: * "space" the buffer of the flattend buffer michael@0: * "arg" ptr to void used by cryptographic resurrect michael@0: * returns resurected context; michael@0: */ michael@0: extern SHA1Context * SHA1_Resurrect(unsigned char *space, void *arg); michael@0: extern void SHA1_Clone(SHA1Context *dest, SHA1Context *src); michael@0: michael@0: /******************************************/ michael@0: michael@0: extern SHA224Context *SHA224_NewContext(void); michael@0: extern void SHA224_DestroyContext(SHA224Context *cx, PRBool freeit); michael@0: extern void SHA224_Begin(SHA224Context *cx); michael@0: extern void SHA224_Update(SHA224Context *cx, const unsigned char *input, michael@0: unsigned int inputLen); michael@0: extern void SHA224_End(SHA224Context *cx, unsigned char *digest, michael@0: unsigned int *digestLen, unsigned int maxDigestLen); michael@0: /* michael@0: ** Export the current state of the SHA-224 hash without appending the standard michael@0: ** padding and length bytes. Produce the digested results in "digest" michael@0: ** "cx" the context michael@0: ** "digest" where the 28 bytes of digest data are stored michael@0: ** "digestLen" where the digest length (28) is stored (optional) michael@0: ** "maxDigestLen" the maximum amount of data that can ever be michael@0: ** stored in "digest" michael@0: */ michael@0: extern void SHA224_EndRaw(SHA224Context *cx, unsigned char *digest, michael@0: unsigned int *digestLen, unsigned int maxDigestLen); michael@0: extern SECStatus SHA224_HashBuf(unsigned char *dest, const unsigned char *src, michael@0: PRUint32 src_length); michael@0: extern SECStatus SHA224_Hash(unsigned char *dest, const char *src); michael@0: extern void SHA224_TraceState(SHA224Context *cx); michael@0: extern unsigned int SHA224_FlattenSize(SHA224Context *cx); michael@0: extern SECStatus SHA224_Flatten(SHA224Context *cx,unsigned char *space); michael@0: extern SHA224Context * SHA224_Resurrect(unsigned char *space, void *arg); michael@0: extern void SHA224_Clone(SHA224Context *dest, SHA224Context *src); michael@0: michael@0: /******************************************/ michael@0: michael@0: extern SHA256Context *SHA256_NewContext(void); michael@0: extern void SHA256_DestroyContext(SHA256Context *cx, PRBool freeit); michael@0: extern void SHA256_Begin(SHA256Context *cx); michael@0: extern void SHA256_Update(SHA256Context *cx, const unsigned char *input, michael@0: unsigned int inputLen); michael@0: extern void SHA256_End(SHA256Context *cx, unsigned char *digest, michael@0: unsigned int *digestLen, unsigned int maxDigestLen); michael@0: /* michael@0: ** Export the current state of the SHA-256 hash without appending the standard michael@0: ** padding and length bytes. Produce the digested results in "digest" michael@0: ** "cx" the context michael@0: ** "digest" where the 32 bytes of digest data are stored michael@0: ** "digestLen" where the digest length (32) is stored (optional) michael@0: ** "maxDigestLen" the maximum amount of data that can ever be michael@0: ** stored in "digest" michael@0: */ michael@0: extern void SHA256_EndRaw(SHA256Context *cx, unsigned char *digest, michael@0: unsigned int *digestLen, unsigned int maxDigestLen); michael@0: extern SECStatus SHA256_HashBuf(unsigned char *dest, const unsigned char *src, michael@0: PRUint32 src_length); michael@0: extern SECStatus SHA256_Hash(unsigned char *dest, const char *src); michael@0: extern void SHA256_TraceState(SHA256Context *cx); michael@0: extern unsigned int SHA256_FlattenSize(SHA256Context *cx); michael@0: extern SECStatus SHA256_Flatten(SHA256Context *cx,unsigned char *space); michael@0: extern SHA256Context * SHA256_Resurrect(unsigned char *space, void *arg); michael@0: extern void SHA256_Clone(SHA256Context *dest, SHA256Context *src); michael@0: michael@0: /******************************************/ michael@0: michael@0: extern SHA512Context *SHA512_NewContext(void); michael@0: extern void SHA512_DestroyContext(SHA512Context *cx, PRBool freeit); michael@0: extern void SHA512_Begin(SHA512Context *cx); michael@0: extern void SHA512_Update(SHA512Context *cx, const unsigned char *input, michael@0: unsigned int inputLen); michael@0: /* michael@0: ** Export the current state of the SHA-512 hash without appending the standard michael@0: ** padding and length bytes. Produce the digested results in "digest" michael@0: ** "cx" the context michael@0: ** "digest" where the 64 bytes of digest data are stored michael@0: ** "digestLen" where the digest length (64) is stored (optional) michael@0: ** "maxDigestLen" the maximum amount of data that can ever be michael@0: ** stored in "digest" michael@0: */ michael@0: extern void SHA512_EndRaw(SHA512Context *cx, unsigned char *digest, michael@0: unsigned int *digestLen, unsigned int maxDigestLen); michael@0: extern void SHA512_End(SHA512Context *cx, unsigned char *digest, michael@0: unsigned int *digestLen, unsigned int maxDigestLen); michael@0: extern SECStatus SHA512_HashBuf(unsigned char *dest, const unsigned char *src, michael@0: PRUint32 src_length); michael@0: extern SECStatus SHA512_Hash(unsigned char *dest, const char *src); michael@0: extern void SHA512_TraceState(SHA512Context *cx); michael@0: extern unsigned int SHA512_FlattenSize(SHA512Context *cx); michael@0: extern SECStatus SHA512_Flatten(SHA512Context *cx,unsigned char *space); michael@0: extern SHA512Context * SHA512_Resurrect(unsigned char *space, void *arg); michael@0: extern void SHA512_Clone(SHA512Context *dest, SHA512Context *src); michael@0: michael@0: /******************************************/ michael@0: michael@0: extern SHA384Context *SHA384_NewContext(void); michael@0: extern void SHA384_DestroyContext(SHA384Context *cx, PRBool freeit); michael@0: extern void SHA384_Begin(SHA384Context *cx); michael@0: extern void SHA384_Update(SHA384Context *cx, const unsigned char *input, michael@0: unsigned int inputLen); michael@0: extern void SHA384_End(SHA384Context *cx, unsigned char *digest, michael@0: unsigned int *digestLen, unsigned int maxDigestLen); michael@0: /* michael@0: ** Export the current state of the SHA-384 hash without appending the standard michael@0: ** padding and length bytes. Produce the digested results in "digest" michael@0: ** "cx" the context michael@0: ** "digest" where the 48 bytes of digest data are stored michael@0: ** "digestLen" where the digest length (48) is stored (optional) michael@0: ** "maxDigestLen" the maximum amount of data that can ever be michael@0: ** stored in "digest" michael@0: */ michael@0: extern void SHA384_EndRaw(SHA384Context *cx, unsigned char *digest, michael@0: unsigned int *digestLen, unsigned int maxDigestLen); michael@0: extern SECStatus SHA384_HashBuf(unsigned char *dest, const unsigned char *src, michael@0: PRUint32 src_length); michael@0: extern SECStatus SHA384_Hash(unsigned char *dest, const char *src); michael@0: extern void SHA384_TraceState(SHA384Context *cx); michael@0: extern unsigned int SHA384_FlattenSize(SHA384Context *cx); michael@0: extern SECStatus SHA384_Flatten(SHA384Context *cx,unsigned char *space); michael@0: extern SHA384Context * SHA384_Resurrect(unsigned char *space, void *arg); michael@0: extern void SHA384_Clone(SHA384Context *dest, SHA384Context *src); michael@0: michael@0: /**************************************** michael@0: * implement TLS 1.0 Pseudo Random Function (PRF) and TLS P_hash function michael@0: */ michael@0: michael@0: extern SECStatus michael@0: TLS_PRF(const SECItem *secret, const char *label, SECItem *seed, michael@0: SECItem *result, PRBool isFIPS); michael@0: michael@0: extern SECStatus michael@0: TLS_P_hash(HASH_HashType hashAlg, const SECItem *secret, const char *label, michael@0: SECItem *seed, SECItem *result, PRBool isFIPS); michael@0: michael@0: /******************************************/ michael@0: /* michael@0: ** Pseudo Random Number Generation. FIPS compliance desirable. michael@0: */ michael@0: michael@0: /* michael@0: ** Initialize the global RNG context and give it some seed input taken michael@0: ** from the system. This function is thread-safe and will only allow michael@0: ** the global context to be initialized once. The seed input is likely michael@0: ** small, so it is imperative that RNG_RandomUpdate() be called with michael@0: ** additional seed data before the generator is used. A good way to michael@0: ** provide the generator with additional entropy is to call michael@0: ** RNG_SystemInfoForRNG(). Note that NSS_Init() does exactly that. michael@0: */ michael@0: extern SECStatus RNG_RNGInit(void); michael@0: michael@0: /* michael@0: ** Update the global random number generator with more seeding michael@0: ** material michael@0: */ michael@0: extern SECStatus RNG_RandomUpdate(const void *data, size_t bytes); michael@0: michael@0: /* michael@0: ** Generate some random bytes, using the global random number generator michael@0: ** object. michael@0: */ michael@0: extern SECStatus RNG_GenerateGlobalRandomBytes(void *dest, size_t len); michael@0: michael@0: /* Destroy the global RNG context. After a call to RNG_RNGShutdown() michael@0: ** a call to RNG_RNGInit() is required in order to use the generator again, michael@0: ** along with seed data (see the comment above RNG_RNGInit()). michael@0: */ michael@0: extern void RNG_RNGShutdown(void); michael@0: michael@0: extern void RNG_SystemInfoForRNG(void); michael@0: michael@0: /* michael@0: * FIPS 186-2 Change Notice 1 RNG Algorithm 1, used both to michael@0: * generate the DSA X parameter and as a generic purpose RNG. michael@0: * michael@0: * The following two FIPS186Change functions are needed for michael@0: * NIST RNG Validation System. michael@0: */ michael@0: michael@0: /* michael@0: * FIPS186Change_GenerateX is now deprecated. It will return SECFailure with michael@0: * the error set to PR_NOT_IMPLEMENTED_ERROR. michael@0: */ michael@0: extern SECStatus michael@0: FIPS186Change_GenerateX(unsigned char *XKEY, michael@0: const unsigned char *XSEEDj, michael@0: unsigned char *x_j); michael@0: michael@0: /* michael@0: * When generating the DSA X parameter, we generate 2*GSIZE bytes michael@0: * of random output and reduce it mod q. michael@0: * michael@0: * Input: w, 2*GSIZE bytes michael@0: * q, DSA_SUBPRIME_LEN bytes michael@0: * Output: xj, DSA_SUBPRIME_LEN bytes michael@0: */ michael@0: extern SECStatus michael@0: FIPS186Change_ReduceModQForDSA(const unsigned char *w, michael@0: const unsigned char *q, michael@0: unsigned char *xj); michael@0: michael@0: /* michael@0: * The following functions are for FIPS poweron self test and FIPS algorithm michael@0: * testing. michael@0: */ michael@0: extern SECStatus michael@0: PRNGTEST_Instantiate(const PRUint8 *entropy, unsigned int entropy_len, michael@0: const PRUint8 *nonce, unsigned int nonce_len, michael@0: const PRUint8 *personal_string, unsigned int ps_len); michael@0: michael@0: extern SECStatus michael@0: PRNGTEST_Reseed(const PRUint8 *entropy, unsigned int entropy_len, michael@0: const PRUint8 *additional, unsigned int additional_len); michael@0: michael@0: extern SECStatus michael@0: PRNGTEST_Generate(PRUint8 *bytes, unsigned int bytes_len, michael@0: const PRUint8 *additional, unsigned int additional_len); michael@0: michael@0: extern SECStatus michael@0: PRNGTEST_Uninstantiate(void); michael@0: michael@0: extern SECStatus michael@0: PRNGTEST_RunHealthTests(void); michael@0: michael@0: /* Generate PQGParams and PQGVerify structs. michael@0: * Length of seed and length of h both equal length of P. michael@0: * All lengths are specified by "j", according to the table above. michael@0: * michael@0: * The verify parameters will conform to FIPS186-1. michael@0: */ michael@0: extern SECStatus michael@0: PQG_ParamGen(unsigned int j, /* input : determines length of P. */ michael@0: PQGParams **pParams, /* output: P Q and G returned here */ michael@0: PQGVerify **pVfy); /* output: counter and seed. */ michael@0: michael@0: /* Generate PQGParams and PQGVerify structs. michael@0: * Length of P specified by j. Length of h will match length of P. michael@0: * Length of SEED in bytes specified in seedBytes. michael@0: * seedBbytes must be in the range [20..255] or an error will result. michael@0: * michael@0: * The verify parameters will conform to FIPS186-1. michael@0: */ michael@0: extern SECStatus michael@0: PQG_ParamGenSeedLen( michael@0: unsigned int j, /* input : determines length of P. */ michael@0: unsigned int seedBytes, /* input : length of seed in bytes.*/ michael@0: PQGParams **pParams, /* output: P Q and G returned here */ michael@0: PQGVerify **pVfy); /* output: counter and seed. */ michael@0: michael@0: /* Generate PQGParams and PQGVerify structs. michael@0: * Length of P specified by L in bits. michael@0: * Length of Q specified by N in bits. michael@0: * Length of SEED in bytes specified in seedBytes. michael@0: * seedBbytes must be in the range [N..L*2] or an error will result. michael@0: * michael@0: * Not that J uses the above table, L is the length exact. L and N must michael@0: * match the table below or an error will result: michael@0: * michael@0: * L N michael@0: * 1024 160 michael@0: * 2048 224 michael@0: * 2048 256 michael@0: * 3072 256 michael@0: * michael@0: * If N or seedBytes are set to zero, then PQG_ParamGenSeedLen will michael@0: * pick a default value (typically the smallest secure value for these michael@0: * variables). michael@0: * michael@0: * The verify parameters will conform to FIPS186-3 using the smallest michael@0: * permissible hash for the key strength. michael@0: */ michael@0: extern SECStatus michael@0: PQG_ParamGenV2( michael@0: unsigned int L, /* input : determines length of P. */ michael@0: unsigned int N, /* input : determines length of Q. */ michael@0: unsigned int seedBytes, /* input : length of seed in bytes.*/ michael@0: PQGParams **pParams, /* output: P Q and G returned here */ michael@0: PQGVerify **pVfy); /* output: counter and seed. */ michael@0: michael@0: michael@0: /* Test PQGParams for validity as DSS PQG values. michael@0: * If vfy is non-NULL, test PQGParams to make sure they were generated michael@0: * using the specified seed, counter, and h values. michael@0: * michael@0: * Return value indicates whether Verification operation ran successfully michael@0: * to completion, but does not indicate if PQGParams are valid or not. michael@0: * If return value is SECSuccess, then *pResult has these meanings: michael@0: * SECSuccess: PQGParams are valid. michael@0: * SECFailure: PQGParams are invalid. michael@0: * michael@0: * Verify the PQG againts the counter, SEED and h. michael@0: * These tests are specified in FIPS 186-3 Appendix A.1.1.1, A.1.1.3, and A.2.2 michael@0: * PQG_VerifyParams will automatically choose the appropriate test. michael@0: */ michael@0: michael@0: extern SECStatus PQG_VerifyParams(const PQGParams *params, michael@0: const PQGVerify *vfy, SECStatus *result); michael@0: michael@0: extern void PQG_DestroyParams(PQGParams *params); michael@0: michael@0: extern void PQG_DestroyVerify(PQGVerify *vfy); michael@0: michael@0: michael@0: /* michael@0: * clean-up any global tables freebl may have allocated after it starts up. michael@0: * This function is not thread safe and should be called only after the michael@0: * library has been quiessed. michael@0: */ michael@0: extern void BL_Cleanup(void); michael@0: michael@0: /* unload freebl shared library from memory */ michael@0: extern void BL_Unload(void); michael@0: michael@0: /************************************************************************** michael@0: * Verify a given Shared library signature * michael@0: **************************************************************************/ michael@0: PRBool BLAPI_SHVerify(const char *name, PRFuncPtr addr); michael@0: michael@0: /************************************************************************** michael@0: * Verify a given filename's signature * michael@0: **************************************************************************/ michael@0: PRBool BLAPI_SHVerifyFile(const char *shName); michael@0: michael@0: /************************************************************************** michael@0: * Verify Are Own Shared library signature * michael@0: **************************************************************************/ michael@0: PRBool BLAPI_VerifySelf(const char *name); michael@0: michael@0: /*********************************************************************/ michael@0: extern const SECHashObject * HASH_GetRawHashObject(HASH_HashType hashType); michael@0: michael@0: extern void BL_SetForkState(PRBool forked); michael@0: michael@0: #ifndef NSS_DISABLE_ECC michael@0: /* michael@0: ** pepare an ECParam structure from DEREncoded params michael@0: */ michael@0: extern SECStatus EC_FillParams(PLArenaPool *arena, michael@0: const SECItem *encodedParams, ECParams *params); michael@0: extern SECStatus EC_DecodeParams(const SECItem *encodedParams, michael@0: ECParams **ecparams); michael@0: extern SECStatus EC_CopyParams(PLArenaPool *arena, ECParams *dstParams, michael@0: const ECParams *srcParams); michael@0: #endif michael@0: michael@0: SEC_END_PROTOS michael@0: michael@0: #endif /* _BLAPI_H_ */