Commit 4f11a8c4 authored by Denis Filatov's avatar Denis Filatov
Browse files

save keys in different compression forms

parent 62d96dc8
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -29,11 +29,11 @@ HashAlgorithm_t CertificateWholeHashAlgorithm(const EtsiTs103097Certificate_t *
                alg = HashAlgorithm_sha384;
                break;
            default:
                if(name) fprintf(stderr, "%s: ERROR: Unknow verification key algorithm\n", name);
                if(name) fprintf(stderr, "%s: ERROR: Unknow verification key algorithm %d\n", name, cert->toBeSigned.verifyKeyIndicator.choice.verificationKey.present);
                return -1;
        }
    } else {
        if(name) fprintf(stderr, "%s: ERROR: Unknow certificate type\n", name);
        if(name) fprintf(stderr, "%s: ERROR: Unknow certificate type %d\n", name, (int)cert->type);
        return -1;
    }
    return alg;
+3 −3
Original line number Diff line number Diff line
@@ -705,7 +705,7 @@ static void * gen_or_load_public_key(ecc_curve_id curveType, char * keyPath)
			}    
			ecc_key_private_save(key, keyPath, _outKeyFormat);
			strcpy(e_pub, EXT_PUB);
			ecc_key_public_save(key, keyPath, _outKeyFormat);
			ecc_key_public_save(key, keyPath, _outKeyFormat, 0);
		} else {
			if (_debug){
				fprintf(stderr, "DEBUG: use pre-generated key %s\n", keyPath);
@@ -780,7 +780,7 @@ static void process_reconstruction_value(void * r_key, void * eph, void * ca, un
		e = cstrcpy(e, EXT_VKEY);
		ecc_key_private_save(u_key, keyPath, _outKeyFormat);
		strcpy(e, EXT_PUB);
		ecc_key_public_save(u_key, keyPath, _outKeyFormat);
		ecc_key_public_save(u_key, keyPath, _outKeyFormat, 0);
		ecc_key_free(u_key);
	}
}
+1 −1
Original line number Diff line number Diff line
@@ -116,7 +116,7 @@ int main(int argc, char ** argv)
            size_t len = cstrlen(argv[argi]);
            pchar_t * path = cstralloc(len + MAX_PATH);
            cstrcpy(path, argv[argi]);
            pchar_t * fname = cstrlastpathelement(path);
            pchar_t * fname = (pchar_t*) cstrlastpathelement(path);
            HANDLE h = FindFirstFile(path, &fd);
    		if(INVALID_HANDLE_VALUE != h) do {
                cstrcpy(fname, fd.cFileName);
+1 −1
Original line number Diff line number Diff line
@@ -63,7 +63,7 @@ int ecc_key_private(void*, char* buf);
int    ecc_key_public(void*, char* x, char* y, int * psign);
int    ecc_key_private_save(void*, const char* path, ecc_format format);
void * ecc_key_private_load(const char* path, ecc_curve_id pk_alg);
int    ecc_key_public_save(void*, const char* path, ecc_format format);
int    ecc_key_public_save(void*, const char* path, ecc_format format, int compressed);
void * ecc_key_public_load(const char* path, ecc_curve_id pk_alg);
void * ecc_key_public_set(ecc_curve_id pk_alg, ecc_point_type ptype, const char * px, const char * py);

+5 −4
Original line number Diff line number Diff line
@@ -337,7 +337,7 @@ void * ecc_key_private_load(const char* path, ecc_curve_id pk_alg)
	return eckey;
}

int ecc_key_public_save(void* key, const char* path, ecc_format format)
int ecc_key_public_save(void* key, const char* path, ecc_format format, int compressed)
{
	EC_KEY   * eckey = (EC_KEY *)key;
	int rc = -1;
@@ -352,16 +352,17 @@ int ecc_key_public_save(void* key, const char* path, ecc_format format)
				char * buf = NULL;
				const EC_POINT * point = EC_KEY_get0_public_key(eckey);
				const EC_GROUP * group = EC_KEY_get0_group(eckey);
				point_conversion_form_t form = compressed ? POINT_CONVERSION_COMPRESSED : POINT_CONVERSION_UNCOMPRESSED;

				if (format == ecc_hex){
					buf = EC_POINT_point2hex(group, point, POINT_CONVERSION_UNCOMPRESSED, NULL);
					buf = EC_POINT_point2hex(group, point, form, NULL);
					len = strlen(buf);
				}
				else if (format == ecc_bin){
					len = EC_POINT_point2oct(group, point, POINT_CONVERSION_UNCOMPRESSED, NULL, 0, NULL);
					len = EC_POINT_point2oct(group, point, form, NULL, 0, NULL);
					if (len > 0){
						buf = OPENSSL_malloc(len + 1);
						if (len != EC_POINT_point2oct(group, point, POINT_CONVERSION_UNCOMPRESSED, (unsigned char*)buf, len, NULL)){
						if (len != EC_POINT_point2oct(group, point, form, (unsigned char*)buf, len, NULL)){
							OPENSSL_free(buf); buf = NULL;
						}
					}
Loading