security/nss/lib/ckfw/ckapi.perl

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/nss/lib/ckfw/ckapi.perl	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,434 @@
     1.4 +#!perl
     1.5 +# 
     1.6 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.7 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.9 +
    1.10 +$copyright = '/* THIS IS A GENERATED FILE */
    1.11 +/* This Source Code Form is subject to the terms of the Mozilla Public
    1.12 + * License, v. 2.0. If a copy of the MPL was not distributed with this
    1.13 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
    1.14 +';
    1.15 +
    1.16 +$count = -1;
    1.17 +$i = 0;
    1.18 +
    1.19 +open(INPUT, "<$ARGV[0]") || die "Can't open $ARGV[0]: $!";
    1.20 +
    1.21 +while(<INPUT>) {
    1.22 +  s/^((?:[^"#]+|"[^"]*")*)(\s*#.*$)/$1/;
    1.23 +  next if (/^\s*$/);
    1.24 +
    1.25 +#  print;
    1.26 +
    1.27 +  /^([\S]+)\s+([^"][\S]*|"[^"]*")/;
    1.28 +  $name = $1;
    1.29 +  $value = $2;
    1.30 +
    1.31 +  if( ($name =~ "FUNCTION") && !($name =~ "CK_FUNCTION") ) {
    1.32 +    $count++;
    1.33 +    $x[$count]{name} = $value;
    1.34 +    $i = 0;
    1.35 +  } else {
    1.36 +    if( $count < 0 ) {
    1.37 +      $value =~ s/"//g;
    1.38 +      $g{$name} = $value;
    1.39 +    } else {
    1.40 +      $x[$count]{args}[$i]{type} = $name;
    1.41 +      $x[$count]{args}[$i]{name} = $value;
    1.42 +      $i++;
    1.43 +      $x[$count]{nargs} = $i; # rewritten each time, oh well
    1.44 +    }
    1.45 +  }
    1.46 +}
    1.47 +
    1.48 +close INPUT;
    1.49 +
    1.50 +# dodump();
    1.51 +doprint();
    1.52 +
    1.53 +sub dodump {
    1.54 +  for( $j = 0; $j <= $count; $j++ ) {
    1.55 +    print "CK_RV CK_ENTRY $x[$j]{name}\n";
    1.56 +    for( $i = 0; $i < $x[$j]{nargs}; $i++ ) {
    1.57 +      print "  $x[$j]{args}[$i]{type} $x[$j]{args}[$i]{name}";
    1.58 +      if( $i == ($x[$j]{nargs} - 1) ) {
    1.59 +        print "\n";
    1.60 +      } else {
    1.61 +        print ",\n";
    1.62 +      }
    1.63 +    }
    1.64 +  }
    1.65 +}
    1.66 +
    1.67 +sub doprint {
    1.68 +open(PROTOTYPE, ">nssckg.h") || die "Can't open nssckg.h: $!";
    1.69 +open(TYPEDEF, ">nssckft.h") || die "Can't open nssckft.h: $!";
    1.70 +open(EPV, ">nssckepv.h") || die "Can't open nssckepv.h: $!";
    1.71 +open(API, ">nssck.api") || die "Can't open nssck.api: $!";
    1.72 +
    1.73 +select PROTOTYPE;
    1.74 +
    1.75 +print $copyright;
    1.76 +print <<EOD
    1.77 +#ifndef NSSCKG_H
    1.78 +#define NSSCKG_H
    1.79 +
    1.80 +/*
    1.81 + * nssckg.h
    1.82 + *
    1.83 + * This automatically-generated header file prototypes the Cryptoki
    1.84 + * functions specified by PKCS#11.
    1.85 + */
    1.86 +
    1.87 +#ifndef NSSCKT_H
    1.88 +#include "nssckt.h"
    1.89 +#endif /* NSSCKT_H */
    1.90 +
    1.91 +EOD
    1.92 +    ;
    1.93 +
    1.94 +for( $j = 0; $j <= $count; $j++ ) {
    1.95 +  print "CK_RV CK_ENTRY $x[$j]{name}\n";
    1.96 +  print "(\n";
    1.97 +  for( $i = 0; $i < $x[$j]{nargs}; $i++ ) {
    1.98 +    print "  $x[$j]{args}[$i]{type} $x[$j]{args}[$i]{name}";
    1.99 +    if( $i == ($x[$j]{nargs} - 1) ) {
   1.100 +      print "\n";
   1.101 +    } else {
   1.102 +      print ",\n";
   1.103 +    }
   1.104 +  }
   1.105 +  print ");\n\n";
   1.106 +}
   1.107 +
   1.108 +print <<EOD
   1.109 +#endif /* NSSCKG_H */
   1.110 +EOD
   1.111 +    ;
   1.112 +
   1.113 +select TYPEDEF;
   1.114 +
   1.115 +print $copyright;
   1.116 +print <<EOD
   1.117 +#ifndef NSSCKFT_H
   1.118 +#define NSSCKFT_H
   1.119 +
   1.120 +/*
   1.121 + * nssckft.h
   1.122 + *
   1.123 + * The automatically-generated header file declares a typedef
   1.124 + * each of the Cryptoki functions specified by PKCS#11.
   1.125 + */
   1.126 +
   1.127 +#ifndef NSSCKT_H
   1.128 +#include "nssckt.h"
   1.129 +#endif /* NSSCKT_H */
   1.130 +
   1.131 +EOD
   1.132 +    ;
   1.133 +
   1.134 +for( $j = 0; $j <= $count; $j++ ) {
   1.135 +#  print "typedef CK_RV (CK_ENTRY *CK_$x[$j]{name})(\n";
   1.136 +  print "typedef CK_CALLBACK_FUNCTION(CK_RV, CK_$x[$j]{name})(\n";
   1.137 +  for( $i = 0; $i < $x[$j]{nargs}; $i++ ) {
   1.138 +    print "  $x[$j]{args}[$i]{type} $x[$j]{args}[$i]{name}";
   1.139 +    if( $i == ($x[$j]{nargs} - 1) ) {
   1.140 +      print "\n";
   1.141 +    } else {
   1.142 +      print ",\n";
   1.143 +    }
   1.144 +  }
   1.145 +  print ");\n\n";
   1.146 +}
   1.147 +
   1.148 +print <<EOD
   1.149 +#endif /* NSSCKFT_H */
   1.150 +EOD
   1.151 +    ;
   1.152 +
   1.153 +select EPV;
   1.154 +
   1.155 +print $copyright;
   1.156 +print <<EOD
   1.157 +#ifndef NSSCKEPV_H
   1.158 +#define NSSCKEPV_H
   1.159 +
   1.160 +/*
   1.161 + * nssckepv.h
   1.162 + *
   1.163 + * This automatically-generated header file defines the type
   1.164 + * CK_FUNCTION_LIST specified by PKCS#11.
   1.165 + */
   1.166 +
   1.167 +#ifndef NSSCKT_H
   1.168 +#include "nssckt.h"
   1.169 +#endif /* NSSCKT_H */
   1.170 +
   1.171 +#ifndef NSSCKFT_H
   1.172 +#include "nssckft.h"
   1.173 +#endif /* NSSCKFT_H */
   1.174 +
   1.175 +#include "nssckp.h"
   1.176 +
   1.177 +struct CK_FUNCTION_LIST {
   1.178 +  CK_VERSION version;
   1.179 +EOD
   1.180 +    ;
   1.181 +
   1.182 +for( $j = 0; $j <= $count; $j++ ) {
   1.183 +  print "  CK_$x[$j]{name} $x[$j]{name};\n";
   1.184 +}
   1.185 +
   1.186 +print <<EOD
   1.187 +};
   1.188 +
   1.189 +#include "nsscku.h"
   1.190 +
   1.191 +#endif /* NSSCKEPV_H */
   1.192 +EOD
   1.193 +    ;
   1.194 +
   1.195 +select API;
   1.196 +
   1.197 +print $copyright;
   1.198 +print <<EOD
   1.199 +
   1.200 +/*
   1.201 + * nssck.api
   1.202 + *
   1.203 + * This automatically-generated file is used to generate a set of
   1.204 + * Cryptoki entry points within the object space of a Module using
   1.205 + * the NSS Cryptoki Framework.
   1.206 + *
   1.207 + * The Module should have a .c file with the following:
   1.208 + *
   1.209 + *  #define MODULE_NAME name
   1.210 + *  #define INSTANCE_NAME instance
   1.211 + *  #include "nssck.api"
   1.212 + *
   1.213 + * where "name" is some module-specific name that can be used to
   1.214 + * disambiguate various modules.  This included file will then
   1.215 + * define the actual Cryptoki routines which pass through to the
   1.216 + * Framework calls.  All routines, except C_GetFunctionList, will
   1.217 + * be prefixed with the name; C_GetFunctionList will be generated
   1.218 + * to return an entry-point vector with these routines.  The
   1.219 + * instance specified should be the basic instance of NSSCKMDInstance.
   1.220 + *
   1.221 + * If, prior to including nssck.api, the .c file also specifies
   1.222 + *
   1.223 + *  #define DECLARE_STRICT_CRYTPOKI_NAMES
   1.224 + *
   1.225 + * Then a set of "stub" routines not prefixed with the name will
   1.226 + * be included.  This would allow the combined module and framework
   1.227 + * to be used in applications which are hard-coded to use the
   1.228 + * PKCS#11 names (instead of going through the EPV).  Please note
   1.229 + * that such applications should be careful resolving symbols when
   1.230 + * more than one PKCS#11 module is loaded.
   1.231 + */
   1.232 +
   1.233 +#ifndef MODULE_NAME
   1.234 +#error "Error: MODULE_NAME must be defined."
   1.235 +#endif /* MODULE_NAME */
   1.236 +
   1.237 +#ifndef INSTANCE_NAME
   1.238 +#error "Error: INSTANCE_NAME must be defined."
   1.239 +#endif /* INSTANCE_NAME */
   1.240 +
   1.241 +#ifndef NSSCKT_H
   1.242 +#include "nssckt.h"
   1.243 +#endif /* NSSCKT_H */
   1.244 +
   1.245 +#ifndef NSSCKFWT_H
   1.246 +#include "nssckfwt.h"
   1.247 +#endif /* NSSCKFWT_H */
   1.248 +
   1.249 +#ifndef NSSCKFWC_H
   1.250 +#include "nssckfwc.h"
   1.251 +#endif /* NSSCKFWC_H */
   1.252 +
   1.253 +#ifndef NSSCKEPV_H
   1.254 +#include "nssckepv.h"
   1.255 +#endif /* NSSCKEPV_H */
   1.256 +
   1.257 +#define ADJOIN(x,y) x##y
   1.258 +
   1.259 +#define __ADJOIN(x,y) ADJOIN(x,y)
   1.260 +
   1.261 +/*
   1.262 + * The anchor.  This object is used to store an "anchor" pointer in
   1.263 + * the Module's object space, so the wrapper functions can relate
   1.264 + * back to this instance.
   1.265 + */
   1.266 +
   1.267 +static NSSCKFWInstance *fwInstance = (NSSCKFWInstance *)0;
   1.268 +
   1.269 +static CK_RV CK_ENTRY
   1.270 +__ADJOIN(MODULE_NAME,C_Initialize)
   1.271 +(
   1.272 +  CK_VOID_PTR pInitArgs
   1.273 +)
   1.274 +{
   1.275 +  return NSSCKFWC_Initialize(&fwInstance, INSTANCE_NAME, pInitArgs);
   1.276 +}
   1.277 +
   1.278 +#ifdef DECLARE_STRICT_CRYPTOKI_NAMES
   1.279 +CK_RV CK_ENTRY 
   1.280 +C_Initialize
   1.281 +(
   1.282 +  CK_VOID_PTR pInitArgs
   1.283 +)
   1.284 +{
   1.285 +  return __ADJOIN(MODULE_NAME,C_Initialize)(pInitArgs);
   1.286 +}
   1.287 +#endif /* DECLARE_STRICT_CRYPTOKI_NAMES */
   1.288 +
   1.289 +static CK_RV CK_ENTRY
   1.290 +__ADJOIN(MODULE_NAME,C_Finalize)
   1.291 +(
   1.292 +  CK_VOID_PTR pReserved
   1.293 +)
   1.294 +{
   1.295 +  return NSSCKFWC_Finalize(&fwInstance);
   1.296 +}
   1.297 +
   1.298 +#ifdef DECLARE_STRICT_CRYPTOKI_NAMES
   1.299 +CK_RV CK_ENTRY
   1.300 +C_Finalize
   1.301 +(
   1.302 +  CK_VOID_PTR pReserved
   1.303 +)
   1.304 +{
   1.305 +  return __ADJOIN(MODULE_NAME,C_Finalize)(pReserved);
   1.306 +}
   1.307 +#endif /* DECLARE_STRICT_CRYPTOKI_NAMES */
   1.308 +
   1.309 +static CK_RV CK_ENTRY
   1.310 +__ADJOIN(MODULE_NAME,C_GetInfo)
   1.311 +(
   1.312 +  CK_INFO_PTR pInfo
   1.313 +)
   1.314 +{
   1.315 +  return NSSCKFWC_GetInfo(fwInstance, pInfo);
   1.316 +}
   1.317 +
   1.318 +#ifdef DECLARE_STRICT_CRYPTOKI_NAMES
   1.319 +CK_RV CK_ENTRY
   1.320 +C_GetInfo
   1.321 +(
   1.322 +  CK_INFO_PTR pInfo
   1.323 +)
   1.324 +{
   1.325 +  return __ADJOIN(MODULE_NAME,C_GetInfo)(pInfo);
   1.326 +}
   1.327 +#endif /* DECLARE_STRICT_CRYPTOKI_NAMES */
   1.328 +
   1.329 +/*
   1.330 + * C_GetFunctionList is defined at the end.
   1.331 + */
   1.332 +
   1.333 +EOD
   1.334 +    ;
   1.335 +
   1.336 +for( $j = 4; $j <= $count; $j++ ) {
   1.337 +  print "static CK_RV CK_ENTRY\n";
   1.338 +  print "__ADJOIN(MODULE_NAME,$x[$j]{name})\n";
   1.339 +  print "(\n";
   1.340 +  for( $i = 0; $i < $x[$j]{nargs}; $i++ ) {
   1.341 +    print "  $x[$j]{args}[$i]{type} $x[$j]{args}[$i]{name}";
   1.342 +    if( $i == ($x[$j]{nargs} - 1) ) {
   1.343 +      print "\n";
   1.344 +    } else {
   1.345 +      print ",\n";
   1.346 +    }
   1.347 +  }
   1.348 +  print ")\n";
   1.349 +  print "{\n";
   1.350 +  print "  return NSSCKFW$x[$j]{name}(fwInstance, ";
   1.351 +  for( $i = 0; $i < $x[$j]{nargs}; $i++ ) {
   1.352 +    print "$x[$j]{args}[$i]{name}";
   1.353 +    if( $i == ($x[$j]{nargs} - 1) ) {
   1.354 +      print ");\n";
   1.355 +    } else {
   1.356 +      print ", ";
   1.357 +    }
   1.358 +  }
   1.359 +  print "}\n\n";
   1.360 +
   1.361 +  print "#ifdef DECLARE_STRICT_CRYPTOKI_NAMES\n";
   1.362 +  print "CK_RV CK_ENTRY\n";
   1.363 +  print "$x[$j]{name}\n";
   1.364 +  print "(\n";
   1.365 +  for( $i = 0; $i < $x[$j]{nargs}; $i++ ) {
   1.366 +    print "  $x[$j]{args}[$i]{type} $x[$j]{args}[$i]{name}";
   1.367 +    if( $i == ($x[$j]{nargs} - 1) ) {
   1.368 +      print "\n";
   1.369 +    } else {
   1.370 +      print ",\n";
   1.371 +    }
   1.372 +  }
   1.373 +  print ")\n";
   1.374 +  print "{\n";
   1.375 +  print "  return __ADJOIN(MODULE_NAME,$x[$j]{name})(";
   1.376 +  for( $i = 0; $i < $x[$j]{nargs}; $i++ ) {
   1.377 +    print "$x[$j]{args}[$i]{name}";
   1.378 +    if( $i == ($x[$j]{nargs} - 1) ) {
   1.379 +      print ");\n";
   1.380 +    } else {
   1.381 +      print ", ";
   1.382 +    }
   1.383 +  }
   1.384 +  print "}\n";
   1.385 +  print "#endif /* DECLARE_STRICT_CRYPTOKI_NAMES */\n\n";
   1.386 +}
   1.387 +
   1.388 +print <<EOD
   1.389 +static CK_RV CK_ENTRY
   1.390 +__ADJOIN(MODULE_NAME,C_GetFunctionList)
   1.391 +(
   1.392 +  CK_FUNCTION_LIST_PTR_PTR ppFunctionList
   1.393 +);
   1.394 +
   1.395 +static CK_FUNCTION_LIST FunctionList = {
   1.396 +  { 2, 1 },
   1.397 +EOD
   1.398 +    ;
   1.399 +
   1.400 +for( $j = 0; $j <= $count; $j++ ) {
   1.401 +  print "__ADJOIN(MODULE_NAME,$x[$j]{name})";
   1.402 +  if( $j < $count ) {
   1.403 +    print ",\n";
   1.404 +  } else {
   1.405 +    print "\n};\n\n";
   1.406 +  }
   1.407 +}
   1.408 +
   1.409 +print <<EOD
   1.410 +static CK_RV CK_ENTRY
   1.411 +__ADJOIN(MODULE_NAME,C_GetFunctionList)
   1.412 +(
   1.413 +  CK_FUNCTION_LIST_PTR_PTR ppFunctionList
   1.414 +)
   1.415 +{
   1.416 +  *ppFunctionList = &FunctionList;
   1.417 +  return CKR_OK;
   1.418 +}
   1.419 +
   1.420 +/* This one is always present */
   1.421 +CK_RV CK_ENTRY
   1.422 +C_GetFunctionList
   1.423 +(
   1.424 +  CK_FUNCTION_LIST_PTR_PTR ppFunctionList
   1.425 +)
   1.426 +{
   1.427 +  return __ADJOIN(MODULE_NAME,C_GetFunctionList)(ppFunctionList);
   1.428 +}
   1.429 +
   1.430 +#undef __ADJOIN
   1.431 +
   1.432 +EOD
   1.433 +    ;
   1.434 +
   1.435 +select STDOUT;
   1.436 +
   1.437 +}

mercurial