~ubuntu-branches/ubuntu/lucid/seamonkey/lucid-security

« back to all changes in this revision

Viewing changes to security/nss-fips/lib/util/secalgid.c

  • Committer: Bazaar Package Importer
  • Author(s): Fabien Tassin
  • Date: 2008-07-29 21:29:02 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080729212902-spm9kpvchp9udwbw
Tags: 1.1.11+nobinonly-0ubuntu1
* New security upstream release: 1.1.11 (LP: #218534)
  Fixes USN-602-1, USN-619-1, USN-623-1 and USN-629-1
* Refresh diverged patch:
  - update debian/patches/80_security_build.patch
* Fix FTBFS with missing -lfontconfig
  - add debian/patches/11_fix_ftbfs_with_fontconfig.patch
  - update debian/patches/series
* Build with default gcc (hardy: 4.2, intrepid: 4.3)
  - update debian/rules
  - update debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ***** BEGIN LICENSE BLOCK *****
 
2
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
3
 *
 
4
 * The contents of this file are subject to the Mozilla Public License Version
 
5
 * 1.1 (the "License"); you may not use this file except in compliance with
 
6
 * the License. You may obtain a copy of the License at
 
7
 * http://www.mozilla.org/MPL/
 
8
 *
 
9
 * Software distributed under the License is distributed on an "AS IS" basis,
 
10
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
11
 * for the specific language governing rights and limitations under the
 
12
 * License.
 
13
 *
 
14
 * The Original Code is the Netscape security libraries.
 
15
 *
 
16
 * The Initial Developer of the Original Code is
 
17
 * Netscape Communications Corporation.
 
18
 * Portions created by the Initial Developer are Copyright (C) 1994-2000
 
19
 * the Initial Developer. All Rights Reserved.
 
20
 *
 
21
 * Contributor(s):
 
22
 *
 
23
 * Alternatively, the contents of this file may be used under the terms of
 
24
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 
25
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
26
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
27
 * of those above. If you wish to allow use of your version of this file only
 
28
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
29
 * use your version of this file under the terms of the MPL, indicate your
 
30
 * decision by deleting the provisions above and replace them with the notice
 
31
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
32
 * the provisions above, a recipient may use your version of this file under
 
33
 * the terms of any one of the MPL, the GPL or the LGPL.
 
34
 *
 
35
 * ***** END LICENSE BLOCK ***** */
 
36
 
 
37
#include "secoid.h"
 
38
#include "secder.h"     /* XXX remove this when remove the DERTemplate */
 
39
#include "secasn1.h"
 
40
#include "secitem.h"
 
41
#include "secerr.h"
 
42
 
 
43
/* XXX Old template; want to expunge it eventually. */
 
44
DERTemplate SECAlgorithmIDTemplate[] = {
 
45
    { DER_SEQUENCE,
 
46
          0, NULL, sizeof(SECAlgorithmID) },
 
47
    { DER_OBJECT_ID,
 
48
          offsetof(SECAlgorithmID,algorithm), },
 
49
    { DER_OPTIONAL | DER_ANY,
 
50
          offsetof(SECAlgorithmID,parameters), },
 
51
    { 0, }
 
52
};
 
53
 
 
54
const SEC_ASN1Template SECOID_AlgorithmIDTemplate[] = {
 
55
    { SEC_ASN1_SEQUENCE,
 
56
          0, NULL, sizeof(SECAlgorithmID) },
 
57
    { SEC_ASN1_OBJECT_ID,
 
58
          offsetof(SECAlgorithmID,algorithm), },
 
59
    { SEC_ASN1_OPTIONAL | SEC_ASN1_ANY,
 
60
          offsetof(SECAlgorithmID,parameters), },
 
61
    { 0, }
 
62
};
 
63
 
 
64
SECOidTag
 
65
SECOID_GetAlgorithmTag(SECAlgorithmID *id)
 
66
{
 
67
    if (id == NULL || id->algorithm.data == NULL)
 
68
        return SEC_OID_UNKNOWN;
 
69
 
 
70
    return SECOID_FindOIDTag (&(id->algorithm));
 
71
}
 
72
 
 
73
SECStatus
 
74
SECOID_SetAlgorithmID(PRArenaPool *arena, SECAlgorithmID *id, SECOidTag which,
 
75
                      SECItem *params)
 
76
{
 
77
    SECOidData *oiddata;
 
78
    PRBool add_null_param;
 
79
 
 
80
    oiddata = SECOID_FindOIDByTag(which);
 
81
    if ( !oiddata ) {
 
82
        PORT_SetError(SEC_ERROR_INVALID_ALGORITHM);
 
83
        return SECFailure;
 
84
    }
 
85
 
 
86
    if (SECITEM_CopyItem(arena, &id->algorithm, &oiddata->oid))
 
87
        return SECFailure;
 
88
 
 
89
    switch (which) {
 
90
      case SEC_OID_MD2:
 
91
      case SEC_OID_MD4:
 
92
      case SEC_OID_MD5:
 
93
      case SEC_OID_SHA1:
 
94
      case SEC_OID_SHA256:
 
95
      case SEC_OID_SHA384:
 
96
      case SEC_OID_SHA512:
 
97
      case SEC_OID_PKCS1_RSA_ENCRYPTION:
 
98
      case SEC_OID_PKCS1_MD2_WITH_RSA_ENCRYPTION:
 
99
      case SEC_OID_PKCS1_MD4_WITH_RSA_ENCRYPTION:
 
100
      case SEC_OID_PKCS1_MD5_WITH_RSA_ENCRYPTION:
 
101
      case SEC_OID_PKCS1_SHA1_WITH_RSA_ENCRYPTION:
 
102
      case SEC_OID_PKCS1_SHA256_WITH_RSA_ENCRYPTION:
 
103
      case SEC_OID_PKCS1_SHA384_WITH_RSA_ENCRYPTION:
 
104
      case SEC_OID_PKCS1_SHA512_WITH_RSA_ENCRYPTION:
 
105
        add_null_param = PR_TRUE;
 
106
        break;
 
107
      default:
 
108
        add_null_param = PR_FALSE;
 
109
        break;
 
110
    }
 
111
 
 
112
    if (params) {
 
113
        /*
 
114
         * I am specifically *not* enforcing the following assertion
 
115
         * (by following it up with an error and a return of failure)
 
116
         * because I do not want to introduce any change in the current
 
117
         * behavior.  But I do want for us to notice if the following is
 
118
         * ever true, because I do not think it should be so and probably
 
119
         * signifies an error/bug somewhere.
 
120
         */
 
121
        PORT_Assert(!add_null_param || (params->len == 2
 
122
                                        && params->data[0] == SEC_ASN1_NULL
 
123
                                        && params->data[1] == 0));
 
124
        if (SECITEM_CopyItem(arena, &id->parameters, params)) {
 
125
            return SECFailure;
 
126
        }
 
127
    } else {
 
128
        /*
 
129
         * Again, this is not considered an error.  But if we assume
 
130
         * that nobody tries to set the parameters field themselves
 
131
         * (but always uses this routine to do that), then we should
 
132
         * not hit the following assertion.  Unless they forgot to zero
 
133
         * the structure, which could also be a bad (and wrong) thing.
 
134
         */
 
135
        PORT_Assert(id->parameters.data == NULL);
 
136
 
 
137
        if (add_null_param) {
 
138
            (void) SECITEM_AllocItem(arena, &id->parameters, 2);
 
139
            if (id->parameters.data == NULL) {
 
140
                return SECFailure;
 
141
            }
 
142
            id->parameters.data[0] = SEC_ASN1_NULL;
 
143
            id->parameters.data[1] = 0;
 
144
        }
 
145
    }
 
146
 
 
147
    return SECSuccess;
 
148
}
 
149
 
 
150
SECStatus
 
151
SECOID_CopyAlgorithmID(PRArenaPool *arena, SECAlgorithmID *to, SECAlgorithmID *from)
 
152
{
 
153
    SECStatus rv;
 
154
 
 
155
    rv = SECITEM_CopyItem(arena, &to->algorithm, &from->algorithm);
 
156
    if (rv) return rv;
 
157
    rv = SECITEM_CopyItem(arena, &to->parameters, &from->parameters);
 
158
    return rv;
 
159
}
 
160
 
 
161
void SECOID_DestroyAlgorithmID(SECAlgorithmID *algid, PRBool freeit)
 
162
{
 
163
    SECITEM_FreeItem(&algid->parameters, PR_FALSE);
 
164
    SECITEM_FreeItem(&algid->algorithm, PR_FALSE);
 
165
    if(freeit == PR_TRUE)
 
166
        PORT_Free(algid);
 
167
}
 
168
 
 
169
SECComparison
 
170
SECOID_CompareAlgorithmID(SECAlgorithmID *a, SECAlgorithmID *b)
 
171
{
 
172
    SECComparison rv;
 
173
 
 
174
    rv = SECITEM_CompareItem(&a->algorithm, &b->algorithm);
 
175
    if (rv) return rv;
 
176
    rv = SECITEM_CompareItem(&a->parameters, &b->parameters);
 
177
    return rv;
 
178
}
 
179
 
 
180
/* This functions simply returns the address of the above-declared template. */
 
181
SEC_ASN1_CHOOSER_IMPLEMENT(SECOID_AlgorithmIDTemplate)
 
182