| 1 | /****************************************************************************** |
|---|
| 2 | * (c)2011 Broadcom Corporation |
|---|
| 3 | * |
|---|
| 4 | * This program is the proprietary software of Broadcom Corporation and/or its licensors, |
|---|
| 5 | * and may only be used, duplicated, modified or distributed pursuant to the terms and |
|---|
| 6 | * conditions of a separate, written license agreement executed between you and Broadcom |
|---|
| 7 | * (an "Authorized License"). Except as set forth in an Authorized License, Broadcom grants |
|---|
| 8 | * no license (express or implied), right to use, or waiver of any kind with respect to the |
|---|
| 9 | * Software, and Broadcom expressly reserves all rights in and to the Software and all |
|---|
| 10 | * intellectual property rights therein. IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU |
|---|
| 11 | * HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY |
|---|
| 12 | * NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE. |
|---|
| 13 | * |
|---|
| 14 | * Except as expressly set forth in the Authorized License, |
|---|
| 15 | * |
|---|
| 16 | * 1. This program, including its structure, sequence and organization, constitutes the valuable trade |
|---|
| 17 | * secrets of Broadcom, and you shall use all reasonable efforts to protect the confidentiality thereof, |
|---|
| 18 | * and to use this information only in connection with your use of Broadcom integrated circuit products. |
|---|
| 19 | * |
|---|
| 20 | * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" |
|---|
| 21 | * AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR |
|---|
| 22 | * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO |
|---|
| 23 | * THE SOFTWARE. BROADCOM SPECIFICALLY DISCLAIMS ANY AND ALL IMPLIED WARRANTIES |
|---|
| 24 | * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, |
|---|
| 25 | * LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION |
|---|
| 26 | * OR CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF |
|---|
| 27 | * USE OR PERFORMANCE OF THE SOFTWARE. |
|---|
| 28 | * |
|---|
| 29 | * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR ITS |
|---|
| 30 | * LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR |
|---|
| 31 | * EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO YOUR |
|---|
| 32 | * USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF |
|---|
| 33 | * THE POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT |
|---|
| 34 | * ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE |
|---|
| 35 | * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF |
|---|
| 36 | * ANY LIMITED REMEDY. |
|---|
| 37 | * |
|---|
| 38 | * $brcm_Workfile: ecc.h $ |
|---|
| 39 | * $brcm_Revision: 1 $ |
|---|
| 40 | * $brcm_Date: 11/8/11 2:43p $ |
|---|
| 41 | * |
|---|
| 42 | * Module Description: |
|---|
| 43 | * |
|---|
| 44 | * Revision History: |
|---|
| 45 | * |
|---|
| 46 | * $brcm_Log: /nexus/lib/dtcp_ip/include/ecc.h $ |
|---|
| 47 | * |
|---|
| 48 | * 1 11/8/11 2:43p leisun |
|---|
| 49 | * SWSECURITY-86: Including original license term for bcrypt |
|---|
| 50 | * |
|---|
| 51 | *****************************************************************************/ |
|---|
| 52 | /****************************************************************************** |
|---|
| 53 | * ECC implementation is from "FreeMe" open source, see bellow for license term. |
|---|
| 54 | A license???? For anonymously published software? Yes! The purpose |
|---|
| 55 | here is to outline how I would like the software used. Putting |
|---|
| 56 | together all this has been a lot of work, and I hope people can |
|---|
| 57 | respect the purpose behind the software, as spelled out here. |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | 1. The purpose of this software is to re-assert your rights over |
|---|
| 61 | fair use of audio files that you have legally purchased or |
|---|
| 62 | otherwise obtained legally. Please use it for that purpose only. |
|---|
| 63 | Do not use it to unprotect files you don't have a legal right to, |
|---|
| 64 | or to unprotect legal files for the purpose of re-distributing |
|---|
| 65 | them to others who do not have a legal right to the content. In |
|---|
| 66 | other words, in use of this software obey traditional copyright |
|---|
| 67 | laws -- but the DMCA may be completely ignored as far as this |
|---|
| 68 | license concerned (although you must accept responsibility for |
|---|
| 69 | ignoring this law, since it is enforceable). |
|---|
| 70 | |
|---|
| 71 | 2. This is free software, without any warranties, guarantees, or any |
|---|
| 72 | assurance that it will work as described. It relies on certain |
|---|
| 73 | other software (from Microsoft) operating as it currently does, |
|---|
| 74 | so I don't take any responsibility for what happens if Microsoft |
|---|
| 75 | updates their software to render this useless, or even if they |
|---|
| 76 | put bombs in their new software to erase all your files if they |
|---|
| 77 | detect this software. But I sure hope they wouldn't do that. |
|---|
| 78 | *********************************************************************/ |
|---|
| 79 | |
|---|
| 80 | /* |
|---|
| 81 | * If the "neg" field of the BIGNUM struct is set, then this point is |
|---|
| 82 | * the identity. This is a terrible way to do this, since it's not |
|---|
| 83 | * clear what the future of this flag is -- however, for now it works, |
|---|
| 84 | * and it's fast... |
|---|
| 85 | */ |
|---|
| 86 | |
|---|
| 87 | typedef struct eccpt_st { |
|---|
| 88 | BIGNUM *x, *y; |
|---|
| 89 | } ECCpt; |
|---|
| 90 | |
|---|
| 91 | typedef struct eccparam_st { |
|---|
| 92 | BIGNUM *modulus; /* Curve is over Z_modulus */ |
|---|
| 93 | BIGNUM *a, *b; /* Curve coefficients */ |
|---|
| 94 | BIGNUM *n; /* Order of Generator */ |
|---|
| 95 | ECCpt generator; /* Generator for our operations */ |
|---|
| 96 | ECCpt pubkey; /* Public key */ |
|---|
| 97 | BIGNUM *privkey; /* Corresponding private key */ |
|---|
| 98 | } ECC; |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | ECC *ECC_new_set(BIGNUM * p, BIGNUM * a, BIGNUM * b, ECCpt g, BIGNUM *n); |
|---|
| 102 | void ECC_free(ECC * ecc); |
|---|
| 103 | |
|---|
| 104 | void ECCpt_init(ECCpt * pt); |
|---|
| 105 | void ECCpt_free(ECCpt * pt); |
|---|
| 106 | |
|---|
| 107 | int ECCpt_is_valid_pt(ECCpt * a, ECC * ecc); |
|---|
| 108 | int ECCpt_is_equal(ECCpt * a, ECCpt * b); |
|---|
| 109 | void ECCpt_add(ECCpt * r, ECCpt * a, ECCpt * b, ECC * ecc); |
|---|
| 110 | void ECCpt_mul(ECCpt * r, ECCpt * a, BIGNUM * n, ECC * ecc); |
|---|