ecc_impl.h revision 1
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc/* BEGIN CSTYLED */
e2cf88ac9d753a00c17aa235f6afdc76574fe3a6Quaker Fang/* ***** BEGIN LICENSE BLOCK *****
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Version: MPL 1.1/GPL 2.0/LGPL 2.1
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * The contents of this file are subject to the Mozilla Public License Version
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * 1.1 (the "License"); you may not use this file except in compliance with
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * the License. You may obtain a copy of the License at
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Software distributed under the License is distributed on an "AS IS" basis,
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * for the specific language governing rights and limitations under the
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * License.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * The Original Code is the Netscape security libraries.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * The Initial Developer of the Original Code is
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Netscape Communications Corporation.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Portions created by the Initial Developer are Copyright (C) 1994-2000
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * the Initial Developer. All Rights Reserved.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Contributor(s):
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Dr Vipul Gupta <vipul.gupta@sun.com> and
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Douglas Stebila <douglas@stebila.ca>, Sun Microsystems Laboratories
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Alternatively, the contents of this file may be used under the terms of
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * either the GNU General Public License Version 2 or later (the "GPL"), or
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * in which case the provisions of the GPL or the LGPL are applicable instead
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * of those above. If you wish to allow use of your version of this file only
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * under the terms of either the GPL or the LGPL, and not to allow others to
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * use your version of this file under the terms of the MPL, indicate your
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * decision by deleting the provisions above and replace them with the notice
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * and other provisions required by the GPL or the LGPL. If you do not delete
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * the provisions above, a recipient may use your version of this file under
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * the terms of any one of the MPL, the GPL or the LGPL.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * ***** END LICENSE BLOCK ***** */
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Sun elects to use this software under the MPL license.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcextern "C" {
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc#endif /* _KERNEL */
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc#define EC_MAX_DIGEST_LEN 1024 /* max digest that can be signed */
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc#define EC_MAX_POINT_LEN 145 /* max len of DER encoded Q */
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc#define EC_MAX_VALUE_LEN 72 /* max len of ANSI X9.62 private value d */
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc#define EC_MAX_SIG_LEN 144 /* max signature len for supported curves */
e2cf88ac9d753a00c17aa235f6afdc76574fe3a6Quaker Fang#define EC_MAX_OID_LEN 10 /* max length of OID buffer */
e2cf88ac9d753a00c17aa235f6afdc76574fe3a6Quaker Fang * Various structures and definitions from NSS are here.
e2cf88ac9d753a00c17aa235f6afdc76574fe3a6Quaker Fang#define PORT_ArenaAlloc(a, n, f) kmem_alloc((n), (f))
e2cf88ac9d753a00c17aa235f6afdc76574fe3a6Quaker Fang#define PORT_ArenaZAlloc(a, n, f) kmem_zalloc((n), (f))
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc#define PORT_ZFree(x, n) (bzero((x), (n)), kmem_free((x), (n)))
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc#define PORT_FreeArena(a, b)
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc#define CHECK_SEC_OK(func) if (SECSuccess != (rv = func)) goto cleanup
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxctypedef enum {
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc unsigned char *data;
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc unsigned int len;
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc SECItem poly; /* irreducible binary polynomial for (GF2m) */
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * the only coefficient of trinomial
e2cf88ac9d753a00c17aa235f6afdc76574fe3a6Quaker Fang * field element (X9.62 section 4.3.3)
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * octet stream.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc SECItem version; /* As per SEC 1, Appendix C, Section C.4 */
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxctypedef enum _SECStatus {
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc#define RNG_GenerateGlobalRandomBytes(p,l) ecc_knzero_random_generator((p), (l))
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc (pkcs11_get_nzero_urandom((p), (l)) < 0 ? CKR_DEVICE_ERROR : CKR_OK)
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc#define CHECK_MPI_OK(func) if (MP_OKAY > (err = func)) goto cleanup
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc CHECK_MPI_OK(mp_read_unsigned_octets((mp), (it).data, (it).len))
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcextern int ecc_knzero_random_generator(uint8_t *, size_t);
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcextern SECStatus EC_DecodeParams(const SECItem *, ECParams **, int);
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcextern SECItem * SECITEM_AllocItem(PRArenaPool *, SECItem *, unsigned int, int);
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcextern SECStatus SECITEM_CopyItem(PRArenaPool *, SECItem *, const SECItem *,
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcextern SECStatus EC_NewKey(ECParams *ecParams, ECPrivateKey **privKey, int);
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcextern SECStatus ECDSA_SignDigest(ECPrivateKey *, SECItem *, const SECItem *,
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcextern SECStatus ECDSA_VerifyDigest(ECPublicKey *, const SECItem *,
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc const SECItem *, int);
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcextern SECStatus ECDH_Derive(SECItem *, ECParams *, SECItem *, boolean_t,
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcextern SECStatus EC_CopyParams(PRArenaPool *, ECParams *, const ECParams *);
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcextern SECStatus EC_ValidatePublicKey(ECParams *, SECItem *, int);
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcextern SECStatus ECDSA_SignDigestWithSeed(ECPrivateKey *, SECItem *,
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc const SECItem *, const unsigned char *, const int kblen, int);
e2cf88ac9d753a00c17aa235f6afdc76574fe3a6Quaker Fang const unsigned char *, int, int);
e2cf88ac9d753a00c17aa235f6afdc76574fe3a6Quaker Fangextern void EC_FreeParams(ECParams *, boolean_t);
e2cf88ac9d753a00c17aa235f6afdc76574fe3a6Quaker Fangextern SECStatus EC_NewKeyFromSeed(ECParams *ecParams, ECPrivateKey **privKey,
e2cf88ac9d753a00c17aa235f6afdc76574fe3a6Quaker Fangextern void EC_FreePrivateKey(ECPrivateKey *, boolean_t);
e2cf88ac9d753a00c17aa235f6afdc76574fe3a6Quaker Fangextern void EC_FreePublicKey(ECPublicKey *, boolean_t);
e2cf88ac9d753a00c17aa235f6afdc76574fe3a6Quaker Fangextern void EC_FreeDerivedKey(SECItem *, boolean_t);
e2cf88ac9d753a00c17aa235f6afdc76574fe3a6Quaker Fangextern void SECITEM_ZfreeItem(SECItem *, boolean_t);
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc#endif /* _ECC_IMPL_H */
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc/* END CSTYLED */