tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ml_dsa.c (3142B)


      1 /*
      2 *
      3 * This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifdef FREEBL_NO_DEPEND
      8 #include "stubs.h"
      9 #endif
     10 
     11 #include "prerror.h"
     12 #include "secerr.h"
     13 
     14 #include "prtypes.h"
     15 #include "prinit.h"
     16 #include "blapi.h"
     17 #include "secitem.h"
     18 #include "blapit.h"
     19 #include "secport.h"
     20 #include "nssilock.h"
     21 #include "secrng.h"
     22 #include "ml_dsat.h"
     23 
     24 /* include other ml-dsa library specific includes here */
     25 
     26 /* this is private to this function and can be changed at will */
     27 struct MLDSAContextStr {
     28    PLArenaPool *arena;
     29    MLDSAPrivateKey *privKey;
     30    MLDSAPublicKey *pubKey;
     31    CK_HEDGE_TYPE hedgeType;
     32    CK_ML_DSA_PARAMETER_SET_TYPE paramSet;
     33    /* other ml-dsa lowelevel library require values and contexts */
     34 };
     35 
     36 /*
     37 ** Generate and return a new DSA public and private key pair,
     38 **  both of which are encoded into a single DSAPrivateKey struct.
     39 **  "params" is a pointer to the PQG parameters for the domain
     40 **  Uses a random seed.
     41 */
     42 SECStatus
     43 MLDSA_NewKey(CK_ML_DSA_PARAMETER_SET_TYPE paramSet, SECItem *seed,
     44             MLDSAPrivateKey *privKey, MLDSAPublicKey *pubKey)
     45 {
     46    /* needs to support returning the seed in the private key
     47     * (if seed is not supplied) or generating the key using the seed
     48     * (if it is supplied) if seed is supplied, it must be the correct
     49     * length */
     50    PORT_SetError(SEC_ERROR_INVALID_ARGS);
     51    return SECFailure;
     52 }
     53 
     54 /*
     55 * we don't have a streaming interace, so use our own local context
     56 * to keep track of things */
     57 SECStatus
     58 MLDSA_SignInit(MLDSAPrivateKey *key, CK_HEDGE_TYPE hedgeType,
     59               const SECItem *sgnCtx, MLDSAContext **ctx)
     60 {
     61    /* if hedgeType is CKH_DETERMINISTIC_REQUIRED, otherwise it
     62     * should generate a HEDGE signature, can stash this value
     63     * if the library takes the hedge parameter in a later call */
     64    PORT_SetError(SEC_ERROR_INVALID_ARGS);
     65    return SECFailure;
     66 }
     67 
     68 SECStatus
     69 MLDSA_SignUpdate(MLDSAContext *ctx, const SECItem *data)
     70 {
     71    /* streaming interface. should not return a signature yet.
     72     * if the library can't do streaming, we need to buffer */
     73    PORT_SetError(SEC_ERROR_INVALID_ARGS);
     74    return SECFailure;
     75 }
     76 
     77 SECStatus
     78 MLDSA_SignFinal(MLDSAContext *ctx, SECItem *signature)
     79 {
     80    /* produce the actual signature, may need the key, so it needs to be
     81     * stashed in ML_DSA_SignInit */
     82    PORT_SetError(SEC_ERROR_INVALID_ARGS);
     83    return SECFailure;
     84 }
     85 
     86 /*
     87 * we don't have a streaming interace, so use our own local context
     88 * to keep track of things */
     89 SECStatus
     90 MLDSA_VerifyInit(MLDSAPublicKey *key, const SECItem *sgnCtx, MLDSAContext **ctx)
     91 {
     92    PORT_SetError(SEC_ERROR_INVALID_ARGS);
     93    return SECFailure;
     94 }
     95 
     96 SECStatus
     97 MLDSA_VerifyUpdate(MLDSAContext *ctx, const SECItem *data)
     98 {
     99    /* like Sign, a streaming interface some rules about buffering */
    100    PORT_SetError(SEC_ERROR_INVALID_ARGS);
    101    return SECFailure;
    102 }
    103 
    104 SECStatus
    105 MLDSA_VerifyFinal(MLDSAContext *ctx, const SECItem *signature)
    106 {
    107    PORT_SetError(SEC_ERROR_INVALID_ARGS);
    108    return SECFailure;
    109 }