Back to index

lightning-sunbird  0.9+nobinonly
preenc.h
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil -*- */
00002 
00003 /*
00004  * Fortezza support is removed.
00005  *
00006  * ***** BEGIN LICENSE BLOCK *****
00007  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00008  *
00009  * The contents of this file are subject to the Mozilla Public License Version
00010  * 1.1 (the "License"); you may not use this file except in compliance with
00011  * the License. You may obtain a copy of the License at
00012  * http://www.mozilla.org/MPL/
00013  *
00014  * Software distributed under the License is distributed on an "AS IS" basis,
00015  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00016  * for the specific language governing rights and limitations under the
00017  * License.
00018  *
00019  * The Original Code is the Netscape security libraries.
00020  *
00021  * The Initial Developer of the Original Code is
00022  * Netscape Communications Corporation.
00023  * Portions created by the Initial Developer are Copyright (C) 1994-2000
00024  * the Initial Developer. All Rights Reserved.
00025  *
00026  * Contributor(s):
00027  *
00028  * Alternatively, the contents of this file may be used under the terms of
00029  * either the GNU General Public License Version 2 or later (the "GPL"), or
00030  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00031  * in which case the provisions of the GPL or the LGPL are applicable instead
00032  * of those above. If you wish to allow use of your version of this file only
00033  * under the terms of either the GPL or the LGPL, and not to allow others to
00034  * use your version of this file under the terms of the MPL, indicate your
00035  * decision by deleting the provisions above and replace them with the notice
00036  * and other provisions required by the GPL or the LGPL. If you do not delete
00037  * the provisions above, a recipient may use your version of this file under
00038  * the terms of any one of the MPL, the GPL or the LGPL.
00039  *
00040  * ***** END LICENSE BLOCK ***** */
00041 /* $Id: preenc.h,v 1.6 2005/08/16 03:42:26 nelsonb%netscape.com Exp $ */
00042 
00043 /* Fortezza support is removed.
00044  * This file remains so that old programs will continue to compile,
00045  * But this functionality is no longer supported or implemented.
00046  */
00047 
00048 #include "seccomon.h"
00049 #include "prio.h"
00050 
00051 typedef struct PEHeaderStr PEHeader;
00052 
00053 #define PE_MIME_TYPE "application/pre-encrypted"
00054 
00055 typedef struct PEFortezzaHeaderStr PEFortezzaHeader;
00056 typedef struct PEFortezzaGeneratedHeaderStr PEFortezzaGeneratedHeader;
00057 typedef struct PEFixedKeyHeaderStr PEFixedKeyHeader;
00058 typedef struct PERSAKeyHeaderStr PERSAKeyHeader;
00059 
00060 struct PEFortezzaHeaderStr {
00061     unsigned char key[12];      
00062     unsigned char iv[24];       
00063     unsigned char hash[20];     
00064     unsigned char serial[8];    
00065 };
00066 
00067 struct PEFortezzaGeneratedHeaderStr {
00068     unsigned char key[12];      
00069     unsigned char iv[24];       
00070     unsigned char hash[20];     
00071     unsigned char Ra[128];      
00072     unsigned char Y[128];       
00073 };
00074 
00075 struct PEFixedKeyHeaderStr {
00076     unsigned char pkcs11Mech[4];  
00077     unsigned char labelLen[2];       
00078     unsigned char keyIDLen[2];       
00079     unsigned char ivLen[2];   
00080     unsigned char keyLen[2];         
00081     unsigned char data[1];    
00082 };
00083 
00084 struct PERSAKeyHeaderStr {
00085     unsigned char pkcs11Mech[4];  
00086     unsigned char issuerLen[2];      
00087     unsigned char serialLen[2];      
00088     unsigned char ivLen[2];   
00089     unsigned char keyLen[2];         
00090     unsigned char data[1];    
00091 };
00092 
00093 #define PEFIXED_Label(header) (header->data)
00094 #define PEFIXED_KeyID(header) (&header->data[GetInt2(header->labelLen)])
00095 #define PEFIXED_IV(header) (&header->data[GetInt2(header->labelLen)\
00096                                           +GetInt2(header->keyIDLen)])
00097 #define PEFIXED_Key(header) (&header->data[GetInt2(header->labelLen)\
00098                      +GetInt2(header->keyIDLen)+GetInt2(header->keyLen)])
00099 #define PERSA_Issuer(header) (header->data)
00100 #define PERSA_Serial(header) (&header->data[GetInt2(header->issuerLen)])
00101 #define PERSA_IV(header) (&header->data[GetInt2(header->issuerLen)\
00102                                           +GetInt2(header->serialLen)])
00103 #define PERSA_Key(header) (&header->data[GetInt2(header->issuerLen)\
00104                      +GetInt2(header->serialLen)+GetInt2(header->keyLen)])
00105 struct PEHeaderStr {
00106     unsigned char magic  [2];             
00107     unsigned char len    [2];             
00108     unsigned char type   [2];             
00109     unsigned char version[2];             
00110     union {
00111         PEFortezzaHeader          fortezza;
00112         PEFortezzaGeneratedHeader g_fortezza;
00113        PEFixedKeyHeader          fixed;
00114        PERSAKeyHeader            rsa;
00115     } u;
00116 };
00117 
00118 #define PE_CRYPT_INTRO_LEN 8
00119 #define PE_INTRO_LEN 4
00120 #define PE_BASE_HEADER_LEN  8
00121 
00122 #define PRE_BLOCK_SIZE 8         
00123 
00124 
00125 #define GetInt2(c) ((c[0] << 8) | c[1])
00126 #define GetInt4(c) (((unsigned long)c[0] << 24)|((unsigned long)c[1] << 16)\
00127                      |((unsigned long)c[2] << 8)| ((unsigned long)c[3]))
00128 #define PutInt2(c,i) ((c[1] = (i) & 0xff), (c[0] = ((i) >> 8) & 0xff))
00129 #define PutInt4(c,i) ((c[0]=((i) >> 24) & 0xff),(c[1]=((i) >> 16) & 0xff),\
00130                      (c[2] = ((i) >> 8) & 0xff), (c[3] = (i) & 0xff))
00131 
00132 #define PRE_MAGIC           0xc0de
00133 #define PRE_VERSION         0x1010
00134 #define PRE_FORTEZZA_FILE   0x00ff  
00135 #define PRE_FORTEZZA_STREAM 0x00f5  
00136 #define PRE_FORTEZZA_GEN_STREAM    0x00f6  
00137 #define PRE_FIXED_FILE             0x000f  
00138 #define PRE_RSA_FILE        0x001f  
00139 #define PRE_FIXED_STREAM    0x0005  
00140 
00141 PEHeader *SSL_PreencryptedStreamToFile(PRFileDesc *fd, PEHeader *,
00142                                    int *headerSize);
00143 
00144 PEHeader *SSL_PreencryptedFileToStream(PRFileDesc *fd, PEHeader *,
00145                                    int *headerSize);
00146