/** Perform on the ECC system @return CRYPT_OK if successful */ int ecc_test(void) { void *modulus, *order; ecc_point *G, *GG; int i, err, primality; if ((err = mp_init_multi(&modulus, &order, NULL)) != CRYPT_OK) { return err; } G = ltc_ecc_new_point(); GG = ltc_ecc_new_point(); if (G == NULL || GG == NULL) { mp_clear_multi(modulus, order, NULL); ltc_ecc_del_point(G); ltc_ecc_del_point(GG); return CRYPT_MEM; } for (i = 0; ltc_ecc_sets[i].size; i++) { #if 0 OPRINTF("Testing %d\n", ltc_ecc_sets[i].size); #endif if ((err = mp_read_radix(modulus, (char *)ltc_ecc_sets[i].prime, 16)) != CRYPT_OK) { goto done; } if ((err = mp_read_radix(order, (char *)ltc_ecc_sets[i].order, 16)) != CRYPT_OK) { goto done; } /* is prime actually prime? */ if ((err = mp_prime_is_prime(modulus, 8, &primality)) != CRYPT_OK) { goto done; } if (primality == 0) { err = CRYPT_FAIL_TESTVECTOR; goto done; } /* is order prime ? */ if ((err = mp_prime_is_prime(order, 8, &primality)) != CRYPT_OK) { goto done; } if (primality == 0) { err = CRYPT_FAIL_TESTVECTOR; goto done; } if ((err = mp_read_radix(G->x, (char *)ltc_ecc_sets[i].Gx, 16)) != CRYPT_OK) { goto done; } if ((err = mp_read_radix(G->y, (char *)ltc_ecc_sets[i].Gy, 16)) != CRYPT_OK) { goto done; } mp_set(G->z, 1); /* then we should have G == (order + 1)G */ if ((err = mp_add_d(order, 1, order)) != CRYPT_OK) { goto done; } if ((err = ltc_mp.ecc_ptmul(order, G, GG, modulus, 1)) != CRYPT_OK) { goto done; } if (mp_cmp(G->x, GG->x) != LTC_MP_EQ || mp_cmp(G->y, GG->y) != LTC_MP_EQ) { err = CRYPT_FAIL_TESTVECTOR; goto done; } } err = CRYPT_OK; done: ltc_ecc_del_point(GG); ltc_ecc_del_point(G); mp_clear_multi(order, modulus, NULL); return err; }
/** Performs a self-test of the Noekeon block cipher @return CRYPT_OK if functional, CRYPT_NOP if self-test has been disabled */ int noekeon_test(void) { #ifndef LTC_TEST return CRYPT_NOP; #else static const struct { int keylen; unsigned char key[16], pt[16], ct[16]; } tests[] = { { 16, { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, { 0x18, 0xa6, 0xec, 0xe5, 0x28, 0xaa, 0x79, 0x73, 0x28, 0xb2, 0xc0, 0x91, 0xa0, 0x2f, 0x54, 0xc5} } }; symmetric_key key; unsigned char tmp[2][16]; int err, i, y; for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) { zeromem(&key, sizeof(key)); if ((err = noekeon_setup(tests[i].key, tests[i].keylen, 0, &key)) != CRYPT_OK) { return err; } noekeon_ecb_encrypt(tests[i].pt, tmp[0], &key); noekeon_ecb_decrypt(tmp[0], tmp[1], &key); if (XMEMCMP(tmp[0], tests[i].ct, 16) || XMEMCMP(tmp[1], tests[i].pt, 16)) { #if 0 OPRINTF("\n\nTest %d failed\n", i); if (XMEMCMP(tmp[0], tests[i].ct, 16)) { OPRINTF("CT: "); for (i = 0; i < 16; i++) { OPRINTF("%02x ", tmp[0][i]); } OPRINTF("\n"); } else { OPRINTF("PT: "); for (i = 0; i < 16; i++) { OPRINTF("%02x ", tmp[1][i]); } OPRINTF("\n"); } #endif return CRYPT_FAIL_TESTVECTOR; } /* now see if we can encrypt all zero bytes 1000 times, decrypt and come back where we started */ for (y = 0; y < 16; y++) tmp[0][y] = 0; for (y = 0; y < 1000; y++) noekeon_ecb_encrypt(tmp[0], tmp[0], &key); for (y = 0; y < 1000; y++) noekeon_ecb_decrypt(tmp[0], tmp[0], &key); for (y = 0; y < 16; y++) if (tmp[0][y] != 0) return CRYPT_FAIL_TESTVECTOR; } return CRYPT_OK; #endif }
/** Self-test the hash @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled */ int rmd128_test(void) { #ifndef LTC_TEST return CRYPT_NOP; #else static const struct { char *msg; unsigned char md[16]; } tests[] = { { "", { 0xcd, 0xf2, 0x62, 0x13, 0xa1, 0x50, 0xdc, 0x3e, 0xcb, 0x61, 0x0f, 0x18, 0xf6, 0xb3, 0x8b, 0x46 } }, { "a", { 0x86, 0xbe, 0x7a, 0xfa, 0x33, 0x9d, 0x0f, 0xc7, 0xcf, 0xc7, 0x85, 0xe7, 0x2f, 0x57, 0x8d, 0x33 } }, { "abc", { 0xc1, 0x4a, 0x12, 0x19, 0x9c, 0x66, 0xe4, 0xba, 0x84, 0x63, 0x6b, 0x0f, 0x69, 0x14, 0x4c, 0x77 } }, { "message digest", { 0x9e, 0x32, 0x7b, 0x3d, 0x6e, 0x52, 0x30, 0x62, 0xaf, 0xc1, 0x13, 0x2d, 0x7d, 0xf9, 0xd1, 0xb8 } }, { "abcdefghijklmnopqrstuvwxyz", { 0xfd, 0x2a, 0xa6, 0x07, 0xf7, 0x1d, 0xc8, 0xf5, 0x10, 0x71, 0x49, 0x22, 0xb3, 0x71, 0x83, 0x4e } }, { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", { 0xd1, 0xe9, 0x59, 0xeb, 0x17, 0x9c, 0x91, 0x1f, 0xae, 0xa4, 0x62, 0x4c, 0x60, 0xc5, 0xc7, 0x02 } } }; int x; unsigned char buf[16]; hash_state md; for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) { rmd128_init(&md); rmd128_process(&md, (unsigned char *)tests[x].msg, strlen(tests[x].msg)); rmd128_done(&md, buf); if (XMEMCMP(buf, tests[x].md, 16) != 0) { #if 0 OPRINTF("Failed test %d\n", x); #endif return CRYPT_FAIL_TESTVECTOR; } } return CRYPT_OK; #endif }
/** Self-test the hash @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled */ int rmd320_test(void) { #ifndef LTC_TEST return CRYPT_NOP; #else static const struct { char *msg; unsigned char md[40]; } tests[] = { { "", { 0x22, 0xd6, 0x5d, 0x56, 0x61, 0x53, 0x6c, 0xdc, 0x75, 0xc1, 0xfd, 0xf5, 0xc6, 0xde, 0x7b, 0x41, 0xb9, 0xf2, 0x73, 0x25, 0xeb, 0xc6, 0x1e, 0x85, 0x57, 0x17, 0x7d, 0x70, 0x5a, 0x0e, 0xc8, 0x80, 0x15, 0x1c, 0x3a, 0x32, 0xa0, 0x08, 0x99, 0xb8 } }, { "a", { 0xce, 0x78, 0x85, 0x06, 0x38, 0xf9, 0x26, 0x58, 0xa5, 0xa5, 0x85, 0x09, 0x75, 0x79, 0x92, 0x6d, 0xda, 0x66, 0x7a, 0x57, 0x16, 0x56, 0x2c, 0xfc, 0xf6, 0xfb, 0xe7, 0x7f, 0x63, 0x54, 0x2f, 0x99, 0xb0, 0x47, 0x05, 0xd6, 0x97, 0x0d, 0xff, 0x5d } }, { "abc", { 0xde, 0x4c, 0x01, 0xb3, 0x05, 0x4f, 0x89, 0x30, 0xa7, 0x9d, 0x09, 0xae, 0x73, 0x8e, 0x92, 0x30, 0x1e, 0x5a, 0x17, 0x08, 0x5b, 0xef, 0xfd, 0xc1, 0xb8, 0xd1, 0x16, 0x71, 0x3e, 0x74, 0xf8, 0x2f, 0xa9, 0x42, 0xd6, 0x4c, 0xdb, 0xc4, 0x68, 0x2d } }, { "message digest", { 0x3a, 0x8e, 0x28, 0x50, 0x2e, 0xd4, 0x5d, 0x42, 0x2f, 0x68, 0x84, 0x4f, 0x9d, 0xd3, 0x16, 0xe7, 0xb9, 0x85, 0x33, 0xfa, 0x3f, 0x2a, 0x91, 0xd2, 0x9f, 0x84, 0xd4, 0x25, 0xc8, 0x8d, 0x6b, 0x4e, 0xff, 0x72, 0x7d, 0xf6, 0x6a, 0x7c, 0x01, 0x97 } }, { "abcdefghijklmnopqrstuvwxyz", { 0xca, 0xbd, 0xb1, 0x81, 0x0b, 0x92, 0x47, 0x0a, 0x20, 0x93, 0xaa, 0x6b, 0xce, 0x05, 0x95, 0x2c, 0x28, 0x34, 0x8c, 0xf4, 0x3f, 0xf6, 0x08, 0x41, 0x97, 0x51, 0x66, 0xbb, 0x40, 0xed, 0x23, 0x40, 0x04, 0xb8, 0x82, 0x44, 0x63, 0xe6, 0xb0, 0x09 } }, { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", { 0xd0, 0x34, 0xa7, 0x95, 0x0c, 0xf7, 0x22, 0x02, 0x1b, 0xa4, 0xb8, 0x4d, 0xf7, 0x69, 0xa5, 0xde, 0x20, 0x60, 0xe2, 0x59, 0xdf, 0x4c, 0x9b, 0xb4, 0xa4, 0x26, 0x8c, 0x0e, 0x93, 0x5b, 0xbc, 0x74, 0x70, 0xa9, 0x69, 0xc9, 0xd0, 0x72, 0xa1, 0xac } } }; int x; unsigned char buf[40]; hash_state md; for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) { rmd320_init(&md); rmd320_process(&md, (unsigned char *)tests[x].msg, strlen(tests[x].msg)); rmd320_done(&md, buf); if (XMEMCMP(buf, tests[x].md, 40) != 0) { #if 0 OPRINTF("Failed test %d\n", x); #endif return CRYPT_FAIL_TESTVECTOR; } } return CRYPT_OK; #endif }
/** @brief Set the icewm style. * * When icewm changes the style, it writes the new style to the ~/.icewm/theme * or $ICEWM_PRIVCFG/theme file and then restarts. The ~/.icewm/theme file * looks like: * * Theme="Penguins/default.theme" * #Theme="Airforce/default.theme" * ##Theme="Penguins/default.theme" * ###Theme="Pedestals/default.theme" * ####Theme="Penguins/default.theme" * #####Theme="Airforce/default.theme" * ######Theme="Archlinux/default.theme" * #######Theme="Airforce/default.theme" * ########Theme="Airforce/default.theme" * #########Theme="Airforce/default.theme" * ##########Theme="Penguins/default.theme" * * icewm cannot distinguish between system an user styles. The theme name * specifies a directory in the /usr/share/icewm/themes, ~/.icewm/themes or * $ICEWM_PRIVCFG/themes subdirectories. * * When xde-session runs, it sets the ICEWM_PRIVCFG environment variable. * xde-session and associated tools will always set this environment variable * before launching icewm. icewm respects this environment variable and no * special options are necessary when launching icewm. * * The default configuration directory when ICEWM_PRIVCFG is not specified is * ~/.icewm. The location of all other icewm configuration files are in this * directory. xde-session typically sets ICEWM_PRIVCFG to * $XDG_CONFIG_HOME/icewm. */ static void set_style_ICEWM() { FILE *f; struct stat st; char *stylefile, *themerc, *buf, *pos, *end, *line; int n, len; size_t read, total; if (!(stylefile = find_style_ICEWM())) { EPRINTF("cannot find style '%s'\n", options.style); goto no_stylefile; } free(stylefile); len = strlen(wm->pdir) + strlen("/theme") + 1; themerc = calloc(len, sizeof(*themerc)); snprintf(themerc, len, "%s/theme", wm->pdir); if (!(f = fopen(themerc, "r"))) { EPRINTF("%s: %s\n", themerc, strerror(errno)); goto no_themerc; } if (fstat(fileno(f), &st)) { EPRINTF("%s: %s\n", themerc, strerror(errno)); goto no_stat; } buf = calloc(st.st_size + 1, sizeof(*buf)); /* read entire file into buffer */ total = 0; while (total < st.st_size) { read = fread(buf + total, 1, st.st_size - total, f); total += read; if (total >= st.st_size) break; if (ferror(f)) { EPRINTF("%s: %s\n", themerc, strerror(errno)); goto no_buf; } if (feof(f)) break; } len = strlen(options.style) + strlen("Theme=\"\"") + 1; line = calloc(len, sizeof(*line)); snprintf(line, len, "Theme=\"%s\"", options.style); if (strncmp(buf, line, strlen(line)) == 0) { OPRINTF("style %s did not change\n", line); goto no_change; } if (options.dryrun) { } else { OPRINTF("writing new style %s\n", options.style); if (!(f = freopen(themerc, "w", f))) { EPRINTF("%s: %s\n", themerc, strerror(errno)); goto no_change; } fprintf(f, "Theme=\"%s\"\n", options.style); for (n = 0, pos = buf, end = buf + st.st_size; pos < end && n < 10; n++, pos = pos + strlen(pos) + 1) { *strchrnul(pos, '\n') = '\0'; fprintf(f, "#%s\n", pos); } if (options.reload) reload_style_ICEWM(); } no_change: free(line); no_buf: free(buf); no_stat: fclose(f); no_themerc: free(themerc); no_stylefile: return; }