security/nss/lib/freebl/ecl/ecl_curve.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #include "ecl.h"
michael@0 6 #include "ecl-curve.h"
michael@0 7 #include "ecl-priv.h"
michael@0 8 #include <stdlib.h>
michael@0 9 #include <string.h>
michael@0 10
michael@0 11 #define CHECK(func) if ((func) == NULL) { res = 0; goto CLEANUP; }
michael@0 12
michael@0 13 /* Duplicates an ECCurveParams */
michael@0 14 ECCurveParams *
michael@0 15 ECCurveParams_dup(const ECCurveParams * params)
michael@0 16 {
michael@0 17 int res = 1;
michael@0 18 ECCurveParams *ret = NULL;
michael@0 19
michael@0 20 CHECK(ret = (ECCurveParams *) calloc(1, sizeof(ECCurveParams)));
michael@0 21 if (params->text != NULL) {
michael@0 22 CHECK(ret->text = strdup(params->text));
michael@0 23 }
michael@0 24 ret->field = params->field;
michael@0 25 ret->size = params->size;
michael@0 26 if (params->irr != NULL) {
michael@0 27 CHECK(ret->irr = strdup(params->irr));
michael@0 28 }
michael@0 29 if (params->curvea != NULL) {
michael@0 30 CHECK(ret->curvea = strdup(params->curvea));
michael@0 31 }
michael@0 32 if (params->curveb != NULL) {
michael@0 33 CHECK(ret->curveb = strdup(params->curveb));
michael@0 34 }
michael@0 35 if (params->genx != NULL) {
michael@0 36 CHECK(ret->genx = strdup(params->genx));
michael@0 37 }
michael@0 38 if (params->geny != NULL) {
michael@0 39 CHECK(ret->geny = strdup(params->geny));
michael@0 40 }
michael@0 41 if (params->order != NULL) {
michael@0 42 CHECK(ret->order = strdup(params->order));
michael@0 43 }
michael@0 44 ret->cofactor = params->cofactor;
michael@0 45
michael@0 46 CLEANUP:
michael@0 47 if (res != 1) {
michael@0 48 EC_FreeCurveParams(ret);
michael@0 49 return NULL;
michael@0 50 }
michael@0 51 return ret;
michael@0 52 }
michael@0 53
michael@0 54 #undef CHECK
michael@0 55
michael@0 56 /* Construct ECCurveParams from an ECCurveName */
michael@0 57 ECCurveParams *
michael@0 58 EC_GetNamedCurveParams(const ECCurveName name)
michael@0 59 {
michael@0 60 if ((name <= ECCurve_noName) || (ECCurve_pastLastCurve <= name) ||
michael@0 61 (ecCurve_map[name] == NULL)) {
michael@0 62 return NULL;
michael@0 63 } else {
michael@0 64 return ECCurveParams_dup(ecCurve_map[name]);
michael@0 65 }
michael@0 66 }
michael@0 67
michael@0 68 /* Free the memory allocated (if any) to an ECCurveParams object. */
michael@0 69 void
michael@0 70 EC_FreeCurveParams(ECCurveParams * params)
michael@0 71 {
michael@0 72 if (params == NULL)
michael@0 73 return;
michael@0 74 if (params->text != NULL)
michael@0 75 free(params->text);
michael@0 76 if (params->irr != NULL)
michael@0 77 free(params->irr);
michael@0 78 if (params->curvea != NULL)
michael@0 79 free(params->curvea);
michael@0 80 if (params->curveb != NULL)
michael@0 81 free(params->curveb);
michael@0 82 if (params->genx != NULL)
michael@0 83 free(params->genx);
michael@0 84 if (params->geny != NULL)
michael@0 85 free(params->geny);
michael@0 86 if (params->order != NULL)
michael@0 87 free(params->order);
michael@0 88 free(params);
michael@0 89 }

mercurial