mirror of
https://github.com/ultravideo/uvg266.git
synced 2024-11-23 18:14:06 +00:00
Add --key opt
This commit is contained in:
parent
409d2114f0
commit
2e130912cb
45
src/cfg.c
45
src/cfg.c
|
@ -123,6 +123,8 @@ int kvz_config_init(kvz_config *cfg)
|
|||
|
||||
cfg->slices = KVZ_SLICES_NONE;
|
||||
|
||||
cfg->optional_key = NULL;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -134,6 +136,7 @@ int kvz_config_destroy(kvz_config *cfg)
|
|||
FREE_POINTER(cfg->tiles_height_split);
|
||||
FREE_POINTER(cfg->slice_addresses_in_ts);
|
||||
FREE_POINTER(cfg->roi.dqps);
|
||||
FREE_POINTER(cfg->optional_key);
|
||||
}
|
||||
free(cfg);
|
||||
|
||||
|
@ -230,6 +233,43 @@ static int parse_tiles_specification(const char* const arg, int32_t * const ntil
|
|||
return 1;
|
||||
}
|
||||
|
||||
static double parse_number_or_die(const char *numstr,double min, double max)
|
||||
{
|
||||
char *tail;
|
||||
double d = strtod(numstr, &tail);
|
||||
if (*tail)
|
||||
fprintf(stderr,"Expected number\n");
|
||||
else
|
||||
return d;
|
||||
exit(1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_array(const char *array, uint8_t *coeff_key, int size,
|
||||
int min, int max)
|
||||
{
|
||||
char *key = strdup(array);
|
||||
const char delim[] = ",";
|
||||
char *token;
|
||||
int i = 0;
|
||||
|
||||
token = strtok(key, delim);
|
||||
while(token!=NULL&&i<size){
|
||||
coeff_key[i] = (uint8_t)parse_number_or_die(token,min,max);
|
||||
i++;
|
||||
token = strtok(NULL, delim);
|
||||
}
|
||||
if(i>=size && (token != NULL)){
|
||||
fprintf(stderr, "\x1B[31mparsing of the array failed : too many members.\n\x1B[0m");
|
||||
return 0;
|
||||
}
|
||||
else if (i<size){
|
||||
fprintf(stderr, "\x1B[31mparsing of the array failed : too few members.\n\x1B[0m");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int parse_slice_specification(const char* const arg, int32_t * const nslices, int32_t** const array) {
|
||||
const char* current_arg = NULL;
|
||||
int32_t current_value;
|
||||
|
@ -952,6 +992,11 @@ int kvz_config_parse(kvz_config *cfg, const char *name, const char *value)
|
|||
|
||||
return 1;
|
||||
}
|
||||
else if OPT("key"){
|
||||
int size_key = 16;
|
||||
cfg->optional_key = (uint8_t *)malloc(sizeof(uint8_t)*size_key);
|
||||
return parse_array(value,cfg->optional_key,size_key,0,255);
|
||||
}
|
||||
else if OPT("me-early-termination"){
|
||||
int8_t mode = 0;
|
||||
int result = parse_enum(value, me_early_termination_names, &mode);
|
||||
|
|
|
@ -107,6 +107,7 @@ static const struct option long_options[] = {
|
|||
{ "hash", required_argument, NULL, 0 },
|
||||
{"cu-split-termination",required_argument, NULL, 0 },
|
||||
{ "crypto", required_argument, NULL, 0 },
|
||||
{ "key", required_argument, NULL, 0 },
|
||||
{ "me-early-termination",required_argument, NULL, 0 },
|
||||
{ "lossless", no_argument, NULL, 0 },
|
||||
{ "no-lossless", no_argument, NULL, 0 },
|
||||
|
|
|
@ -712,7 +712,7 @@ static void encoder_state_encode_leaf(encoder_state_t * const state)
|
|||
state->ref_qp = state->frame->QP;
|
||||
|
||||
if (cfg->crypto_features) {
|
||||
state->crypto_hdl = kvz_crypto_create();
|
||||
state->crypto_hdl = kvz_crypto_create(&state->encoder_control->cfg);
|
||||
state->crypto_prev_pos = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,22 +26,24 @@ struct crypto_handle_t {
|
|||
};
|
||||
|
||||
|
||||
static const int init_val[32] = {
|
||||
201, 75, 219, 152, 6, 245, 237, 107,
|
||||
179, 194, 81, 29, 66, 98, 198, 0,
|
||||
16, 213, 27, 56, 255, 127, 242, 112,
|
||||
97, 126, 197, 204, 25, 59, 38, 30,
|
||||
};
|
||||
static uint8_t default_IV[16] = {201, 75, 219, 152, 6, 245, 237, 107, 179, 194, 81, 29, 66, 98, 198, 0};
|
||||
static uint8_t default_key[16] = {16, 213, 27, 56, 255, 127, 242, 112, 97, 126, 197, 204, 25, 59, 38, 30};
|
||||
|
||||
|
||||
crypto_handle_t* kvz_crypto_create()
|
||||
crypto_handle_t* kvz_crypto_create(const kvz_config *cfg)
|
||||
{
|
||||
crypto_handle_t* hdl = (crypto_handle_t*)calloc(1, sizeof(crypto_handle_t));
|
||||
|
||||
uint8_t *key;
|
||||
if(cfg->optional_key!=NULL)
|
||||
key = cfg->optional_key;
|
||||
else
|
||||
key = default_key;
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
hdl->iv [i] = init_val[i];
|
||||
hdl->counter[i] = init_val[i + 5];
|
||||
hdl->key[i] = init_val[i + 16];
|
||||
hdl->iv [i] = default_IV[i];
|
||||
hdl->counter[i] = (i<11)? default_IV[5+i] : key[i-11];
|
||||
hdl->key[i] = key[i];
|
||||
}
|
||||
|
||||
hdl->cipher = new cipher_t(hdl->key, CryptoPP::AES::DEFAULT_KEYLENGTH, hdl->iv);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define CRYPTO_H_
|
||||
|
||||
#include "global.h"
|
||||
#include "../cfg.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
@ -20,7 +21,7 @@ extern "C" {
|
|||
|
||||
typedef struct crypto_handle_t crypto_handle_t;
|
||||
|
||||
STUBBED crypto_handle_t* kvz_crypto_create();
|
||||
STUBBED crypto_handle_t* kvz_crypto_create(const kvz_config *cfg);
|
||||
STUBBED void kvz_crypto_decrypt(crypto_handle_t* hdl,
|
||||
const uint8_t *in_stream,
|
||||
int size_bits,
|
||||
|
|
|
@ -320,6 +320,7 @@ typedef struct kvz_config
|
|||
enum kvz_cu_split_termination cu_split_termination; /*!< \since 3.8.0 \brief Mode of cu split termination. */
|
||||
|
||||
enum kvz_crypto_features crypto_features; /*!< \since 3.7.0 */
|
||||
uint8_t *optional_key;
|
||||
|
||||
enum kvz_me_early_termination me_early_termination; /*!< \since 3.8.0 \brief Mode of me early termination. */
|
||||
|
||||
|
|
Loading…
Reference in a new issue