30 #define MAX_HASHLEN 64
31 #define MAX_BLOCKLEN 128
43 #define DEFINE_SHA(bits) \
44 static av_cold void sha ## bits ##_init(void *ctx) \
46 av_sha_init(ctx, bits); \
49 #define DEFINE_SHA512(bits) \
50 static av_cold void sha ## bits ##_init(void *ctx) \
52 av_sha512_init(ctx, bits); \
78 c->
init = sha160_init;
89 c->
init = sha224_init;
100 c->
init = sha256_init;
108 c->
init = sha384_init;
116 c->
init = sha512_init;
150 memcpy(c->
key, key, keylen);
154 for (i = 0; i < c->
keylen; i++)
155 block[i] = c->
key[i] ^ 0x36;
156 for (i = c->
keylen; i < c->blocklen; i++)
170 if (outlen < c->hashlen)
174 for (i = 0; i < c->
keylen; i++)
175 block[i] = c->
key[i] ^ 0x5C;
176 for (i = c->
keylen; i < c->blocklen; i++)
185 const uint8_t *key,
unsigned int keylen,
203 if (!key[keylen - 1])
205 if (!data[datalen - 1])
207 out =
av_hmac_calc(hmac, data, datalen, key, keylen, buf,
sizeof(buf));
208 for (i = 0; i <
out; i++)
209 printf(
"%02x", buf[i]);
215 uint8_t key1[20], key3[131], data3[50];
218 static const uint8_t key2[] =
"Jefe";
219 static const uint8_t data1[] =
"Hi There";
220 static const uint8_t data2[] =
"what do ya want for nothing?";
221 static const uint8_t data4[] =
"Test Using Larger Than Block-Size Key - Hash Key First";
222 static const uint8_t data5[] =
"Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data";
223 static const uint8_t data6[] =
"This is a test using a larger than block-size key and a larger "
224 "than block-size data. The key needs to be hashed before being used"
225 " by the HMAC algorithm.";
226 memset(key1, 0x0b,
sizeof(key1));
227 memset(key3, 0xaa,
sizeof(key3));
228 memset(data3, 0xdd,
sizeof(data3));
236 test(hmac, key1, hmac->
hashlen, data1,
sizeof(data1));
237 test(hmac, key2,
sizeof(key2), data2,
sizeof(data2));
238 test(hmac, key3, hmac->
hashlen, data3,
sizeof(data3));
239 test(hmac, key3, 80, data4,
sizeof(data4));
240 test(hmac, key3, 80, data5,
sizeof(data5));
250 test(hmac, key1,
sizeof(key1), data1,
sizeof(data1));
251 test(hmac, key2,
sizeof(key2), data2,
sizeof(data2));
252 test(hmac, key3, 20, data3,
sizeof(data3));
253 test(hmac, key3,
sizeof(key3), data4,
sizeof(data4));
254 test(hmac, key3,
sizeof(key3), data6,
sizeof(data6));
263 test(hmac, key1,
sizeof(key1), data1,
sizeof(data1));
264 test(hmac, key2,
sizeof(key2), data2,
sizeof(data2));
265 test(hmac, key3, 20, data3,
sizeof(data3));
266 test(hmac, key3,
sizeof(key3), data4,
sizeof(data4));
267 test(hmac, key3,
sizeof(key3), data6,
sizeof(data6));
void av_sha_final(AVSHA *ctx, uint8_t *digest)
Finish hashing and output digest value.
int av_hmac_calc(AVHMAC *c, const uint8_t *data, unsigned int len, const uint8_t *key, unsigned int keylen, uint8_t *out, unsigned int outlen)
Hash an array of data with a key.
void av_sha_update(AVSHA *ctx, const uint8_t *data, unsigned int len)
Update hash value.
ptrdiff_t const GLvoid * data
AVHMAC * av_hmac_alloc(enum AVHMACType type)
Allocate an AVHMAC context.
memory handling functions
void av_md5_update(AVMD5 *ctx, const uint8_t *src, int len)
Update hash value.
Macro definitions for various function/variable attributes.
struct AVMD5 * av_md5_alloc(void)
Allocate an AVMD5 context.
void av_hmac_update(AVHMAC *c, const uint8_t *data, unsigned int len)
Hash data with the HMAC.
struct AVSHA512 * av_sha512_alloc(void)
Allocate an AVSHA512 context.
static void test(const char *pattern, const char *host)
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
void av_hmac_init(AVHMAC *c, const uint8_t *key, unsigned int keylen)
Initialize an AVHMAC context with an authentication key.
uint8_t key[MAX_BLOCKLEN]
void(* final)(void *, uint8_t *)
void av_sha512_update(AVSHA512 *ctx, const uint8_t *data, unsigned int len)
Update hash value.
struct AVSHA * av_sha_alloc(void)
Allocate an AVSHA context.
void av_md5_init(AVMD5 *ctx)
Initialize MD5 hashing.
void av_md5_final(AVMD5 *ctx, uint8_t *dst)
Finish hashing and output digest value.
int av_hmac_final(AVHMAC *c, uint8_t *out, unsigned int outlen)
Finish hashing and output the HMAC digest.
void(* update)(void *, const uint8_t *, int len)
#define DEFINE_SHA512(bits)
void av_hmac_free(AVHMAC *c)
Free an AVHMAC context.
void av_sha512_final(AVSHA512 *ctx, uint8_t *digest)
Finish hashing and output digest value.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
int main(int argc, char **argv)
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...