dst_test.c revision 4124057bf54f0fc75b06b35487130bbd9249ee7f
70e5a7403f0e0a3bd292b8287c5fed5772c15270Automatic Updater * Copyright (C) 1999, 2000 Internet Software Consortium.
cffe50abf66495ee08084f8e1081278a9b589985Brian Wellington * Permission to use, copy, modify, and distribute this software for any
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * purpose with or without fee is hereby granted, provided that the above
cffe50abf66495ee08084f8e1081278a9b589985Brian Wellington * copyright notice and this permission notice appear in all copies.
cffe50abf66495ee08084f8e1081278a9b589985Brian Wellington * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein isc_buffer_init(&sigbuf, sig, sizeof(sig), ISC_BUFFERTYPE_BINARY);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein /* Advance 1 byte for fun */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein isc_buffer_init(&databuf, data, strlen(data), ISC_BUFFERTYPE_TEXT);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein ret = dst_sign(DST_SIGMODE_ALL, key, NULL, &datareg, &sigbuf);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein printf("sign(%d) returned: %s\n", dst_key_alg(key),
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein ret = dst_verify(DST_SIGMODE_ALL, key, NULL, &datareg, &sigreg);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein printf("verify(%d) returned: %s\n", dst_key_alg(key),
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinio(char *name, int id, int alg, int type, isc_mem_t *mctx) {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein ret = dst_key_fromfile(name, id, alg, type, mctx, &key);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein printf("read(%d) returned: %s\n", alg, isc_result_totext(ret));
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein printf("write(%d) returned: %s\n", alg, isc_result_totext(ret));
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeindh(char *name1, int id1, char *name2, int id2, isc_mem_t *mctx) {
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington int type = DST_TYPE_PUBLIC|DST_TYPE_PRIVATE;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington ret = dst_key_fromfile(name1, id1, alg, type, mctx, &key1);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington printf("read(%d) returned: %s\n", alg, isc_result_totext(ret));
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington ret = dst_key_fromfile(name2, id2, alg, type, mctx, &key2);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington printf("read(%d) returned: %s\n", alg, isc_result_totext(ret));
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington printf("write(%d) returned: %s\n", alg, isc_result_totext(ret));
47ad4fad771b9c570bcf57793d6a931e0ca9856cAndreas Gustafsson printf("write(%d) returned: %s\n", alg, isc_result_totext(ret));
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington isc_buffer_init(&b1, array1, sizeof(array1), ISC_BUFFERTYPE_BINARY);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein printf("computesecret() returned: %s\n", isc_result_totext(ret));
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson isc_buffer_init(&b2, array2, sizeof(array2), ISC_BUFFERTYPE_BINARY);
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson ret = dst_computesecret(key2, key1, &b2);
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson printf("computesecret() returned: %s\n", isc_result_totext(ret));
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson if (r1.length != r2.length || memcmp(r1.base, r2.base, r1.length) != 0)
f00075e753b20ece0b4daf68b29044e44c898d89Andreas Gustafsson printf("secret 1: %d bytes\n", r1.length);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington ret = dst_key_generate("test.", alg, 512, 0, 0, 0, mctx, &key);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington printf("generate(%d) returned: %s\n", alg, isc_result_totext(ret));
2103b1d4600dcfb0c28dde10c6c96a867f775f57Brian Wellington unsigned int i;
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington isc_buffer_init(&databuf, data, sizeof data, ISC_BUFFERTYPE_BINARY);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington ret = dst_random_get(sizeof(data), &databuf);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington printf("random() returned: %s\n", isc_result_totext(ret));
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington for (i = 0; i < sizeof data; i++)
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington io("test.", 6204, DST_ALG_DSA, DST_TYPE_PRIVATE|DST_TYPE_PUBLIC, mctx);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington io("test.", 54622, DST_ALG_RSA, DST_TYPE_PRIVATE|DST_TYPE_PUBLIC, mctx);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington io("test.", 0, DST_ALG_DSA, DST_TYPE_PRIVATE|DST_TYPE_PUBLIC, mctx);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington io("test.", 0, DST_ALG_RSA, DST_TYPE_PRIVATE|DST_TYPE_PUBLIC, mctx);
668728fed845b9db9c1423946df03d5fc69f4eeeBrian Wellington/* isc_mem_stats(mctx, stdout);*/