Add SM2 signature algorithm to default provider
[openssl.git] / providers / implementations / signature / sm2sig.c
1 /*
2  * Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 /*
11  * ECDSA low level APIs are deprecated for public use, but still ok for
12  * internal use - SM2 implemetation uses ECDSA_size() function.
13  */
14 #include "internal/deprecated.h"
15
16 #include <string.h> /* memcpy */
17 #include <openssl/crypto.h>
18 #include <openssl/core_dispatch.h>
19 #include <openssl/core_names.h>
20 #include <openssl/dsa.h>
21 #include <openssl/params.h>
22 #include <openssl/evp.h>
23 #include <openssl/err.h>
24 #include "internal/nelem.h"
25 #include "internal/sizes.h"
26 #include "internal/cryptlib.h"
27 #include "prov/providercommonerr.h"
28 #include "prov/implementations.h"
29 #include "prov/provider_ctx.h"
30 #include "crypto/ec.h"
31 #include "crypto/sm2.h"
32 #include "prov/der_sm2.h"
33
34 static OSSL_FUNC_signature_newctx_fn sm2sig_newctx;
35 static OSSL_FUNC_signature_sign_init_fn sm2sig_signature_init;
36 static OSSL_FUNC_signature_verify_init_fn sm2sig_signature_init;
37 static OSSL_FUNC_signature_sign_fn sm2sig_sign;
38 static OSSL_FUNC_signature_verify_fn sm2sig_verify;
39 static OSSL_FUNC_signature_digest_sign_init_fn sm2sig_digest_signverify_init;
40 static OSSL_FUNC_signature_digest_sign_update_fn sm2sig_digest_signverify_update;
41 static OSSL_FUNC_signature_digest_sign_final_fn sm2sig_digest_sign_final;
42 static OSSL_FUNC_signature_digest_verify_init_fn sm2sig_digest_signverify_init;
43 static OSSL_FUNC_signature_digest_verify_update_fn sm2sig_digest_signverify_update;
44 static OSSL_FUNC_signature_digest_verify_final_fn sm2sig_digest_verify_final;
45 static OSSL_FUNC_signature_freectx_fn sm2sig_freectx;
46 static OSSL_FUNC_signature_dupctx_fn sm2sig_dupctx;
47 static OSSL_FUNC_signature_get_ctx_params_fn sm2sig_get_ctx_params;
48 static OSSL_FUNC_signature_gettable_ctx_params_fn sm2sig_gettable_ctx_params;
49 static OSSL_FUNC_signature_set_ctx_params_fn sm2sig_set_ctx_params;
50 static OSSL_FUNC_signature_settable_ctx_params_fn sm2sig_settable_ctx_params;
51 static OSSL_FUNC_signature_get_ctx_md_params_fn sm2sig_get_ctx_md_params;
52 static OSSL_FUNC_signature_gettable_ctx_md_params_fn sm2sig_gettable_ctx_md_params;
53 static OSSL_FUNC_signature_set_ctx_md_params_fn sm2sig_set_ctx_md_params;
54 static OSSL_FUNC_signature_settable_ctx_md_params_fn sm2sig_settable_ctx_md_params;
55
56 /*
57  * What's passed as an actual key is defined by the KEYMGMT interface.
58  * We happen to know that our KEYMGMT simply passes EC structures, so
59  * we use that here too.
60  */
61 typedef struct {
62     OPENSSL_CTX *libctx;
63     char *propq;
64     EC_KEY *ec;
65
66     /*
67      * Flag to determine if the hash function can be changed (1) or not (0)
68      * Because it's dangerous to change during a DigestSign or DigestVerify
69      * operation, this flag is cleared by their Init function, and set again
70      * by their Final function.
71      */
72     unsigned int flag_allow_md : 1;
73     /*
74      * Flag to termine if the 'z' digest needs to be computed and fed to the
75      * hash function.
76      * This flag should be set on initialization and the compuation should
77      * be performed only once, on first update.
78      */
79     unsigned int flag_compute_z_digest : 1;
80
81     char mdname[OSSL_MAX_NAME_SIZE];
82
83     /* The Algorithm Identifier of the combined signature algorithm */
84     unsigned char aid_buf[OSSL_MAX_ALGORITHM_ID_SIZE];
85     unsigned char *aid;
86     size_t  aid_len;
87
88     /* main digest */
89     EVP_MD *md;
90     EVP_MD_CTX *mdctx;
91     size_t mdsize;
92
93     /* SM2 ID used for calculating the Z value */
94     unsigned char *id;
95     size_t id_len;
96 } PROV_SM2_CTX;
97
98 /* TODO: it seems SM2 doesn't need this */
99 static int sm2sig_get_md_nid(const EVP_MD *md)
100 {
101     /*
102      * Because the EC library deals with NIDs, we need to translate.
103      * We do so using EVP_MD_is_a(), and therefore need a name to NID
104      * map.
105      */
106     static const OSSL_ITEM name_to_nid[] = {
107         { NID_sm3,   OSSL_DIGEST_NAME_SM3 },
108     };
109     size_t i;
110     int mdnid = NID_undef;
111
112     if (md == NULL)
113         goto end;
114
115     for (i = 0; i < OSSL_NELEM(name_to_nid); i++) {
116         if (EVP_MD_is_a(md, name_to_nid[i].ptr)) {
117             mdnid = (int)name_to_nid[i].id;
118             break;
119         }
120     }
121
122     if (mdnid == NID_undef)
123         ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_DIGEST);
124
125  end:
126     return mdnid;
127 }
128
129 static void *sm2sig_newctx(void *provctx, const char *propq)
130 {
131     PROV_SM2_CTX *ctx = OPENSSL_zalloc(sizeof(PROV_SM2_CTX));
132
133     if (ctx == NULL)
134         return NULL;
135
136     ctx->libctx = PROV_LIBRARY_CONTEXT_OF(provctx);
137     if (propq != NULL && (ctx->propq = OPENSSL_strdup(propq)) == NULL) {
138         OPENSSL_free(ctx);
139         ctx = NULL;
140         ERR_raise(ERR_LIB_PROV, ERR_R_MALLOC_FAILURE);
141     }
142     /* don't allow to change MD, and in fact there is no such need */
143     ctx->flag_allow_md = 0;
144     return ctx;
145 }
146
147 static int sm2sig_signature_init(void *vpsm2ctx, void *ec)
148 {
149     PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx;
150
151     if (psm2ctx == NULL || ec == NULL || !EC_KEY_up_ref(ec))
152         return 0;
153     EC_KEY_free(psm2ctx->ec);
154     psm2ctx->ec = ec;
155     return 1;
156 }
157
158 static int sm2sig_sign(void *vpsm2ctx, unsigned char *sig, size_t *siglen,
159                        size_t sigsize, const unsigned char *tbs, size_t tbslen)
160 {
161     PROV_SM2_CTX *ctx = (PROV_SM2_CTX *)vpsm2ctx;
162     int ret;
163     unsigned int sltmp;
164     /* SM2 uses ECDSA_size as well */
165     size_t ecsize = ECDSA_size(ctx->ec);
166
167     if (sig == NULL) {
168         *siglen = ecsize;
169         return 1;
170     }
171
172     if (sigsize < (size_t)ecsize)
173         return 0;
174
175     if (ctx->mdsize != 0 && tbslen != ctx->mdsize)
176         return 0;
177
178     ret = sm2_internal_sign(tbs, tbslen, sig, &sltmp, ctx->ec);
179     if (ret <= 0)
180         return 0;
181
182     *siglen = sltmp;
183     return 1;
184 }
185
186 static int sm2sig_verify(void *vpsm2ctx, const unsigned char *sig, size_t siglen,
187                          const unsigned char *tbs, size_t tbslen)
188 {
189     PROV_SM2_CTX *ctx = (PROV_SM2_CTX *)vpsm2ctx;
190
191     if (ctx->mdsize != 0 && tbslen != ctx->mdsize)
192         return 0;
193
194     return sm2_internal_verify(tbs, tbslen, sig, siglen, ctx->ec);
195 }
196
197 static void free_md(PROV_SM2_CTX *ctx)
198 {
199     EVP_MD_CTX_free(ctx->mdctx);
200     EVP_MD_free(ctx->md);
201     ctx->mdctx = NULL;
202     ctx->md = NULL;
203     ctx->mdsize = 0;
204 }
205
206 static int sm2sig_digest_signverify_init(void *vpsm2ctx, const char *mdname,
207                                          void *ec)
208 {
209     PROV_SM2_CTX *ctx = (PROV_SM2_CTX *)vpsm2ctx;
210     int md_nid = NID_undef;
211     WPACKET pkt;
212     int ret = 0;
213
214     free_md(ctx);
215
216     if (!sm2sig_signature_init(vpsm2ctx, ec))
217         return ret;
218
219     ctx->md = EVP_MD_fetch(ctx->libctx, mdname, ctx->propq);
220     if ((md_nid = sm2sig_get_md_nid(ctx->md)) == NID_undef)
221         goto error;
222
223     ctx->mdsize = EVP_MD_size(ctx->md);
224     ctx->mdctx = EVP_MD_CTX_new();
225     if (ctx->mdctx == NULL)
226         goto error;
227
228     /*
229      * TODO(3.0) Should we care about DER writing errors?
230      * All it really means is that for some reason, there's no
231      * AlgorithmIdentifier to be had, but the operation itself is
232      * still valid, just as long as it's not used to construct
233      * anything that needs an AlgorithmIdentifier.
234      */
235     ctx->aid_len = 0;
236     if (WPACKET_init_der(&pkt, ctx->aid_buf, sizeof(ctx->aid_buf))
237         && DER_w_algorithmIdentifier_SM2_with_MD(&pkt, -1, ctx->ec, md_nid)
238         && WPACKET_finish(&pkt)) {
239         WPACKET_get_total_written(&pkt, &ctx->aid_len);
240         ctx->aid = WPACKET_get_curr(&pkt);
241     }
242     WPACKET_cleanup(&pkt);
243
244     if (!EVP_DigestInit_ex(ctx->mdctx, ctx->md, NULL))
245         goto error;
246
247     ctx->flag_compute_z_digest = 1;
248
249     ret = 1;
250
251  error:
252     if (!ret)
253         free_md(ctx);
254     return ret;
255 }
256
257 static int sm2sig_compute_z_digest(PROV_SM2_CTX *ctx)
258 {
259     uint8_t *z = NULL;
260     int ret = 1;
261
262     if (ctx->flag_compute_z_digest) {
263         /* Only do this once */
264         ctx->flag_compute_z_digest = 0;
265
266         if ((z = OPENSSL_zalloc(ctx->mdsize)) == NULL
267             /* get hashed prefix 'z' of tbs message */
268             || !sm2_compute_z_digest(z, ctx->md, ctx->id, ctx->id_len, ctx->ec)
269             || !EVP_DigestUpdate(ctx->mdctx, z, ctx->mdsize))
270             ret = 0;
271         OPENSSL_free(z);
272     }
273
274     return ret;
275 }
276
277 int sm2sig_digest_signverify_update(void *vpsm2ctx, const unsigned char *data,
278                                     size_t datalen)
279 {
280     PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx;
281
282     if (psm2ctx == NULL || psm2ctx->mdctx == NULL)
283         return 0;
284
285     return sm2sig_compute_z_digest(psm2ctx)
286         && EVP_DigestUpdate(psm2ctx->mdctx, data, datalen);
287 }
288
289 int sm2sig_digest_sign_final(void *vpsm2ctx, unsigned char *sig, size_t *siglen,
290                              size_t sigsize)
291 {
292     PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx;
293     unsigned char digest[EVP_MAX_MD_SIZE];
294     unsigned int dlen = 0;
295
296     if (psm2ctx == NULL || psm2ctx->mdctx == NULL)
297         return 0;
298
299     /*
300      * If sig is NULL then we're just finding out the sig size. Other fields
301      * are ignored. Defer to sm2sig_sign.
302      */
303     if (sig != NULL) {
304         if (!(sm2sig_compute_z_digest(psm2ctx)
305               && EVP_DigestFinal_ex(psm2ctx->mdctx, digest, &dlen)))
306             return 0;
307     }
308
309     return sm2sig_sign(vpsm2ctx, sig, siglen, sigsize, digest, (size_t)dlen);
310 }
311
312
313 int sm2sig_digest_verify_final(void *vpsm2ctx, const unsigned char *sig,
314                                size_t siglen)
315 {
316     PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx;
317     unsigned char digest[EVP_MAX_MD_SIZE];
318     unsigned int dlen = 0;
319
320     if (psm2ctx == NULL || psm2ctx->mdctx == NULL)
321         return 0;
322
323     /* SM2 always use SM3 so it's not possible to exceed the limit */
324     if (!(sm2sig_compute_z_digest(psm2ctx)
325           && EVP_DigestFinal_ex(psm2ctx->mdctx, digest, &dlen)))
326         return 0;
327
328     return sm2sig_verify(vpsm2ctx, sig, siglen, digest, (size_t)dlen);
329 }
330
331 static void sm2sig_freectx(void *vpsm2ctx)
332 {
333     PROV_SM2_CTX *ctx = (PROV_SM2_CTX *)vpsm2ctx;
334
335     free_md(ctx);
336     EC_KEY_free(ctx->ec);
337     OPENSSL_free(ctx->id);
338     OPENSSL_free(ctx);
339 }
340
341 static void *sm2sig_dupctx(void *vpsm2ctx)
342 {
343     PROV_SM2_CTX *srcctx = (PROV_SM2_CTX *)vpsm2ctx;
344     PROV_SM2_CTX *dstctx;
345
346     dstctx = OPENSSL_zalloc(sizeof(*srcctx));
347     if (dstctx == NULL)
348         return NULL;
349
350     *dstctx = *srcctx;
351     dstctx->ec = NULL;
352     dstctx->md = NULL;
353     dstctx->mdctx = NULL;
354
355     if (srcctx->ec != NULL && !EC_KEY_up_ref(srcctx->ec))
356         goto err;
357     dstctx->ec = srcctx->ec;
358
359     if (srcctx->md != NULL && !EVP_MD_up_ref(srcctx->md))
360         goto err;
361     dstctx->md = srcctx->md;
362
363     if (srcctx->mdctx != NULL) {
364         dstctx->mdctx = EVP_MD_CTX_new();
365         if (dstctx->mdctx == NULL
366                 || !EVP_MD_CTX_copy_ex(dstctx->mdctx, srcctx->mdctx))
367             goto err;
368     }
369
370     if (srcctx->id != NULL) {
371         dstctx->id = OPENSSL_malloc(srcctx->id_len);
372         if (dstctx->id == NULL)
373             goto err;
374         dstctx->id_len = srcctx->id_len;
375         memcpy(dstctx->id, srcctx->id, srcctx->id_len);
376     }
377
378     return dstctx;
379  err:
380     sm2sig_freectx(dstctx);
381     return NULL;
382 }
383
384 static int sm2sig_get_ctx_params(void *vpsm2ctx, OSSL_PARAM *params)
385 {
386     PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx;
387     OSSL_PARAM *p;
388
389     if (psm2ctx == NULL || params == NULL)
390         return 0;
391
392     p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_ALGORITHM_ID);
393     if (p != NULL
394         && !OSSL_PARAM_set_octet_string(p, psm2ctx->aid, psm2ctx->aid_len))
395         return 0;
396
397     p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_DIGEST_SIZE);
398     if (p != NULL && !OSSL_PARAM_set_size_t(p, psm2ctx->mdsize))
399         return 0;
400
401     p = OSSL_PARAM_locate(params, OSSL_SIGNATURE_PARAM_DIGEST);
402     if (p != NULL && !OSSL_PARAM_set_utf8_string(p, psm2ctx->md == NULL
403                                                     ? psm2ctx->mdname
404                                                     : EVP_MD_name(psm2ctx->md)))
405         return 0;
406
407     return 1;
408 }
409
410 static const OSSL_PARAM known_gettable_ctx_params[] = {
411     OSSL_PARAM_octet_string(OSSL_SIGNATURE_PARAM_ALGORITHM_ID, NULL, 0),
412     OSSL_PARAM_size_t(OSSL_SIGNATURE_PARAM_DIGEST_SIZE, NULL),
413     OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, NULL, 0),
414     OSSL_PARAM_END
415 };
416
417 static const OSSL_PARAM *sm2sig_gettable_ctx_params(ossl_unused void *provctx)
418 {
419     return known_gettable_ctx_params;
420 }
421
422 static int sm2sig_set_ctx_params(void *vpsm2ctx, const OSSL_PARAM params[])
423 {
424     PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx;
425     const OSSL_PARAM *p;
426     char *mdname;
427
428     if (psm2ctx == NULL || params == NULL)
429         return 0;
430
431     p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_DIST_ID);
432     if (p != NULL) {
433         void *tmp_id = NULL;
434         size_t tmp_idlen;
435
436         /*
437          * If the 'z' digest has already been computed, the ID is set too late
438          */
439         if (!psm2ctx->flag_compute_z_digest)
440             return 0;
441
442         if (!OSSL_PARAM_get_octet_string(p, &tmp_id, 0, &tmp_idlen))
443             return 0;
444         OPENSSL_free(psm2ctx->id);
445         psm2ctx->id = tmp_id;
446         psm2ctx->id_len = tmp_idlen;
447     }
448
449     if (psm2ctx->md != NULL) {
450         /*
451          * You cannot set the digest name/size when doing a DigestSign or
452          * DigestVerify.
453          */
454         return 1;
455     }
456
457     p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_DIGEST_SIZE);
458     if (p != NULL && !OSSL_PARAM_get_size_t(p, &psm2ctx->mdsize))
459         return 0;
460
461     /*
462      * We never actually use the mdname, but we do support getting it later.
463      * This can be useful for applications that want to know the MD that they
464      * previously set.
465      */
466     p = OSSL_PARAM_locate_const(params, OSSL_SIGNATURE_PARAM_DIGEST);
467     mdname = psm2ctx->mdname;
468     if (p != NULL
469             && !OSSL_PARAM_get_utf8_string(p, &mdname, sizeof(psm2ctx->mdname)))
470         return 0;
471
472     return 1;
473 }
474
475 static const OSSL_PARAM known_settable_ctx_params[] = {
476     OSSL_PARAM_size_t(OSSL_SIGNATURE_PARAM_DIGEST_SIZE, NULL),
477     OSSL_PARAM_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, NULL, 0),
478     OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_DIST_ID, NULL, 0),
479     OSSL_PARAM_END
480 };
481
482 static const OSSL_PARAM *sm2sig_settable_ctx_params(ossl_unused void *provctx)
483 {
484     /*
485      * TODO(3.0): Should this function return a different set of settable ctx
486      * params if the ctx is being used for a DigestSign/DigestVerify? In that
487      * case it is not allowed to set the digest size/digest name because the
488      * digest is explicitly set as part of the init.
489      */
490     return known_settable_ctx_params;
491 }
492
493 static int sm2sig_get_ctx_md_params(void *vpsm2ctx, OSSL_PARAM *params)
494 {
495     PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx;
496
497     if (psm2ctx->mdctx == NULL)
498         return 0;
499
500     return EVP_MD_CTX_get_params(psm2ctx->mdctx, params);
501 }
502
503 static const OSSL_PARAM *sm2sig_gettable_ctx_md_params(void *vpsm2ctx)
504 {
505     PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx;
506
507     if (psm2ctx->md == NULL)
508         return 0;
509
510     return EVP_MD_gettable_ctx_params(psm2ctx->md);
511 }
512
513 static int sm2sig_set_ctx_md_params(void *vpsm2ctx, const OSSL_PARAM params[])
514 {
515     PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx;
516
517     if (psm2ctx->mdctx == NULL)
518         return 0;
519
520     return EVP_MD_CTX_set_params(psm2ctx->mdctx, params);
521 }
522
523 static const OSSL_PARAM *sm2sig_settable_ctx_md_params(void *vpsm2ctx)
524 {
525     PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx;
526
527     if (psm2ctx->md == NULL)
528         return 0;
529
530     return EVP_MD_settable_ctx_params(psm2ctx->md);
531 }
532
533 const OSSL_DISPATCH sm2_signature_functions[] = {
534     { OSSL_FUNC_SIGNATURE_NEWCTX, (void (*)(void))sm2sig_newctx },
535     { OSSL_FUNC_SIGNATURE_SIGN_INIT, (void (*)(void))sm2sig_signature_init },
536     { OSSL_FUNC_SIGNATURE_SIGN, (void (*)(void))sm2sig_sign },
537     { OSSL_FUNC_SIGNATURE_VERIFY_INIT, (void (*)(void))sm2sig_signature_init },
538     { OSSL_FUNC_SIGNATURE_VERIFY, (void (*)(void))sm2sig_verify },
539     { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT,
540       (void (*)(void))sm2sig_digest_signverify_init },
541     { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_UPDATE,
542       (void (*)(void))sm2sig_digest_signverify_update },
543     { OSSL_FUNC_SIGNATURE_DIGEST_SIGN_FINAL,
544       (void (*)(void))sm2sig_digest_sign_final },
545     { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_INIT,
546       (void (*)(void))sm2sig_digest_signverify_init },
547     { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_UPDATE,
548       (void (*)(void))sm2sig_digest_signverify_update },
549     { OSSL_FUNC_SIGNATURE_DIGEST_VERIFY_FINAL,
550       (void (*)(void))sm2sig_digest_verify_final },
551     { OSSL_FUNC_SIGNATURE_FREECTX, (void (*)(void))sm2sig_freectx },
552     { OSSL_FUNC_SIGNATURE_DUPCTX, (void (*)(void))sm2sig_dupctx },
553     { OSSL_FUNC_SIGNATURE_GET_CTX_PARAMS, (void (*)(void))sm2sig_get_ctx_params },
554     { OSSL_FUNC_SIGNATURE_GETTABLE_CTX_PARAMS,
555       (void (*)(void))sm2sig_gettable_ctx_params },
556     { OSSL_FUNC_SIGNATURE_SET_CTX_PARAMS, (void (*)(void))sm2sig_set_ctx_params },
557     { OSSL_FUNC_SIGNATURE_SETTABLE_CTX_PARAMS,
558       (void (*)(void))sm2sig_settable_ctx_params },
559     { OSSL_FUNC_SIGNATURE_GET_CTX_MD_PARAMS,
560       (void (*)(void))sm2sig_get_ctx_md_params },
561     { OSSL_FUNC_SIGNATURE_GETTABLE_CTX_MD_PARAMS,
562       (void (*)(void))sm2sig_gettable_ctx_md_params },
563     { OSSL_FUNC_SIGNATURE_SET_CTX_MD_PARAMS,
564       (void (*)(void))sm2sig_set_ctx_md_params },
565     { OSSL_FUNC_SIGNATURE_SETTABLE_CTX_MD_PARAMS,
566       (void (*)(void))sm2sig_settable_ctx_md_params },
567     { 0, NULL }
568 };