@@ -20,6 +20,14 @@ static struct aws_hash_vtable s_md5_vtable = {
2020 .provider = "OpenSSL Compatible libcrypto" ,
2121};
2222
23+ static struct aws_hash_vtable s_sha512_vtable = {
24+ .destroy = s_destroy ,
25+ .update = s_update ,
26+ .finalize = s_finalize ,
27+ .alg_name = "SHA512" ,
28+ .provider = "OpenSSL Compatible libcrypto" ,
29+ };
30+
2331static struct aws_hash_vtable s_sha256_vtable = {
2432 .destroy = s_destroy ,
2533 .update = s_update ,
@@ -52,22 +60,14 @@ static void s_destroy(struct aws_hash *hash) {
5260struct aws_hash * aws_md5_default_new (struct aws_allocator * allocator ) {
5361 struct aws_hash * hash = aws_mem_acquire (allocator , sizeof (struct aws_hash ));
5462
55- if (!hash ) {
56- return NULL ;
57- }
58-
5963 hash -> allocator = allocator ;
6064 hash -> vtable = & s_md5_vtable ;
6165 hash -> digest_size = AWS_MD5_LEN ;
6266 EVP_MD_CTX * ctx = g_aws_openssl_evp_md_ctx_table -> new_fn ();
6367 hash -> impl = ctx ;
6468 hash -> good = true;
6569
66- if (!hash -> impl ) {
67- s_destroy (hash );
68- aws_raise_error (AWS_ERROR_OOM );
69- return NULL ;
70- }
70+ AWS_FATAL_ASSERT (hash -> impl );
7171
7272 if (!g_aws_openssl_evp_md_ctx_table -> init_ex_fn (ctx , EVP_md5 (), NULL )) {
7373 s_destroy (hash );
@@ -78,25 +78,38 @@ struct aws_hash *aws_md5_default_new(struct aws_allocator *allocator) {
7878 return hash ;
7979}
8080
81- struct aws_hash * aws_sha256_default_new (struct aws_allocator * allocator ) {
81+ struct aws_hash * aws_sha512_default_new (struct aws_allocator * allocator ) {
8282 struct aws_hash * hash = aws_mem_acquire (allocator , sizeof (struct aws_hash ));
8383
84- if (!hash ) {
84+ hash -> allocator = allocator ;
85+ hash -> vtable = & s_sha512_vtable ;
86+ hash -> digest_size = AWS_SHA512_LEN ;
87+ EVP_MD_CTX * ctx = g_aws_openssl_evp_md_ctx_table -> new_fn ();
88+ hash -> impl = ctx ;
89+ hash -> good = true;
90+
91+ AWS_FATAL_ASSERT (hash -> impl );
92+
93+ if (!g_aws_openssl_evp_md_ctx_table -> init_ex_fn (ctx , EVP_sha512 (), NULL )) {
94+ s_destroy (hash );
95+ aws_raise_error (AWS_ERROR_UNKNOWN );
8596 return NULL ;
8697 }
8798
99+ return hash ;
100+ }
101+
102+ struct aws_hash * aws_sha256_default_new (struct aws_allocator * allocator ) {
103+ struct aws_hash * hash = aws_mem_acquire (allocator , sizeof (struct aws_hash ));
104+
88105 hash -> allocator = allocator ;
89106 hash -> vtable = & s_sha256_vtable ;
90107 hash -> digest_size = AWS_SHA256_LEN ;
91108 EVP_MD_CTX * ctx = g_aws_openssl_evp_md_ctx_table -> new_fn ();
92109 hash -> impl = ctx ;
93110 hash -> good = true;
94111
95- if (!hash -> impl ) {
96- s_destroy (hash );
97- aws_raise_error (AWS_ERROR_OOM );
98- return NULL ;
99- }
112+ AWS_FATAL_ASSERT (hash -> impl );
100113
101114 if (!g_aws_openssl_evp_md_ctx_table -> init_ex_fn (ctx , EVP_sha256 (), NULL )) {
102115 s_destroy (hash );
@@ -110,22 +123,14 @@ struct aws_hash *aws_sha256_default_new(struct aws_allocator *allocator) {
110123struct aws_hash * aws_sha1_default_new (struct aws_allocator * allocator ) {
111124 struct aws_hash * hash = aws_mem_acquire (allocator , sizeof (struct aws_hash ));
112125
113- if (!hash ) {
114- return NULL ;
115- }
116-
117126 hash -> allocator = allocator ;
118127 hash -> vtable = & s_sha1_vtable ;
119128 hash -> digest_size = AWS_SHA1_LEN ;
120129 EVP_MD_CTX * ctx = g_aws_openssl_evp_md_ctx_table -> new_fn ();
121130 hash -> impl = ctx ;
122131 hash -> good = true;
123132
124- if (!hash -> impl ) {
125- s_destroy (hash );
126- aws_raise_error (AWS_ERROR_OOM );
127- return NULL ;
128- }
133+ AWS_FATAL_ASSERT (hash -> impl );
129134
130135 if (!g_aws_openssl_evp_md_ctx_table -> init_ex_fn (ctx , EVP_sha1 (), NULL )) {
131136 s_destroy (hash );
0 commit comments