| 112 | } |
| 113 | |
| 114 | int av_hash_alloc(AVHashContext **ctx, const char *name) |
| 115 | { |
| 116 | AVHashContext *res; |
| 117 | int i; |
| 118 | *ctx = NULL; |
| 119 | for (i = 0; i < NUM_HASHES; i++) |
| 120 | if (av_strcasecmp(name, hashdesc[i].name) == 0) |
| 121 | break; |
| 122 | if (i >= NUM_HASHES) return AVERROR(EINVAL); |
| 123 | res = av_mallocz(sizeof(*res)); |
| 124 | if (!res) return AVERROR(ENOMEM); |
| 125 | res->type = i; |
| 126 | switch (i) { |
| 127 | case MD5: res->ctx = av_md5_alloc(); break; |
| 128 | case MURMUR3: res->ctx = av_murmur3_alloc(); break; |
| 129 | case RIPEMD128: |
| 130 | case RIPEMD160: |
| 131 | case RIPEMD256: |
| 132 | case RIPEMD320: res->ctx = av_ripemd_alloc(); break; |
| 133 | case SHA160: |
| 134 | case SHA224: |
| 135 | case SHA256: res->ctx = av_sha_alloc(); break; |
| 136 | case SHA512_224: |
| 137 | case SHA512_256: |
| 138 | case SHA384: |
| 139 | case SHA512: res->ctx = av_sha512_alloc(); break; |
| 140 | case CRC32: res->crctab = av_crc_get_table(AV_CRC_32_IEEE_LE); break; |
| 141 | case ADLER32: break; |
| 142 | } |
| 143 | if (i != ADLER32 && i != CRC32 && !res->ctx) { |
| 144 | av_free(res); |
| 145 | return AVERROR(ENOMEM); |
| 146 | } |
| 147 | *ctx = res; |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | void av_hash_init(AVHashContext *ctx) |
| 152 | { |