File: aead-decrypt.c

package info (click to toggle)
rtpengine 13.5.1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,676 kB
  • sloc: ansic: 86,775; perl: 59,422; python: 3,193; sh: 1,037; makefile: 687; asm: 211
file content (68 lines) | stat: -rw-r--r-- 1,639 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <assert.h>

#include "crypto.h"
#include "rtplib.h"
#include "log.h"
#include "main.h"
#include "ssrc.h"
#include "rtp.h"
#include "../kernel-module/common_stats.h"


struct rtpengine_config rtpe_config = {
};
int get_local_log_level(unsigned int u) {
	return -1;
}

int main(int argc, char **argv) {
	if (argc < 5) {
		printf("Usage: %s <suite> <key> <salt> <packet>\n", argv[0]);
		printf("Example: %s AEAD_AES_256_GCM \\\n", argv[0]);
		printf("  F4mVFvZGU/S50OXT17xvKHCC/8CV5vgp8OgmAlFpKcc= \\\n");
		printf("  fNAN6151Wc6DgFEZ gAhqUYthx4ivfuWtbtq...\n");
		return 1;
	}

	crypto_init_main();

	str suite;
	suite = STR(argv[1]);
	struct crypto_context cc = {0};
	cc.params.crypto_suite = crypto_find_suite(&suite);
	assert(cc.params.crypto_suite);

	const char *key64 = argv[2];
	const char *salt64 = argv[3];

	size_t len;
	uint8_t *key = g_base64_decode(key64, &len);
	assert(len == cc.params.crypto_suite->master_key_len);
	uint8_t *salt = g_base64_decode(salt64, &len);
	assert(len == cc.params.crypto_suite->master_salt_len);

	memcpy(cc.params.master_key, key, cc.params.crypto_suite->master_key_len);
	memcpy(cc.params.master_salt, salt, cc.params.crypto_suite->master_salt_len);

	const char *pack64 = argv[4];
	uint8_t *pack = g_base64_decode(pack64, &len);
	str s = STR_LEN((char *) pack, len);

	unsigned int roc = 0;

	if (argc >= 6)
		roc = atoi(argv[5]);

	struct ssrc_stats stats = {
		.ext_seq = roc << 16,
	};

	struct ssrc_entry_call se = {
		.stats = &stats,
	};

	int ret = rtp_savp2avp(&s, &cc, &se);
	assert(ret == 0);
	printf("idx %d ROC %d\n", se.stats->ext_seq, se.stats->ext_seq >> 16);
	return 0;
}