mkiiskila commented on a change in pull request #1876: [RFC] Add cryptographic 
HASH driver
URL: https://github.com/apache/mynewt-core/pull/1876#discussion_r295210750
 
 

 ##########
 File path: hw/drivers/hash/src/hash.c
 ##########
 @@ -0,0 +1,144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "hash/hash.h"
+
+int
+hash_custom_process(struct hash_dev *hash, uint16_t algo, const void *inbuf,
+        uint32_t inlen, void *outbuf)
+{
+    int rc;
+    struct hash_generic_context ctx;
+
+    if (!hash_has_support(hash, algo)) {
+        return -1;
+    }
+
+    if (hash->interface.start == NULL || hash->interface.update == NULL ||
+            hash->interface.finish == NULL) {
+        return -1;
+    }
+
+    rc = hash->interface.start(hash, &ctx, algo);
+    if (rc) {
+        return -1;
+    }
+
+    rc = hash->interface.update(hash, &ctx, algo, inbuf, inlen);
+    if (rc) {
+        return -1;
+    }
+
+    rc = hash->interface.finish(hash, &ctx, algo, outbuf);
+    return rc;
+}
+
+int
+hash_custom_start(struct hash_dev *hash, void *ctx, uint16_t algo)
+{
+    if (!hash_has_support(hash, algo)) {
+        return -1;
+    }
+
+    if (hash->interface.start == NULL) {
 
 Review comment:
   Does it make sense to have this check done at runtime? I think I'd rather 
have the code jump to NULL pointer here and crash, rather than pay the 
performance penalty :)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to