You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2019/06/19 09:43:38 UTC

[GitHub] [mynewt-core] mkiiskila commented on a change in pull request #1876: [RFC] Add cryptographic HASH driver

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

 ##########
 File path: hw/drivers/hash/include/hash/hash.h
 ##########
 @@ -0,0 +1,235 @@
+/*
+ * 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.
+ */
+
+#ifndef __HASH_H__
+#define __HASH_H__
+
+#include <inttypes.h>
+#include <stddef.h>
+#include "os/mynewt.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * HASH definitions
+ */
+#define MD5_DIGEST_LEN                 16
+#define SHA1_DIGEST_LEN                20
+#define SHA224_DIGEST_LEN              28
+#define SHA256_DIGEST_LEN              32
+#define HASH_MAX_DIGEST_LEN            SHA256_DIGEST_LEN
+
+#define SHA256_BLOCK_LEN               64  /* 512 bits */
+#define HASH_MAX_BLOCK_LEN             SHA256_BLOCK_LEN
+
+/*
+ * MCU specific context structs
+ */
+#include "hash_context.h"
+
+struct hash_generic_context {
+    union {
+        struct hash_md5_context md5ctx;
+        struct hash_sha1_context sha1ctx;
+        struct hash_sha224_context sha224ctx;
+        struct hash_sha256_context sha256ctx;
+    };
+};
+
+/*
+ * Driver capabilities
+ */
+#define HASH_ALGO_MD5                  0x0001
+#define HASH_ALGO_SHA1                 0x0002
+#define HASH_ALGO_SHA224               0x0004
+#define HASH_ALGO_SHA256               0x0008
+
+struct hash_dev;
+
+typedef int (* hash_start_op_func_t)(struct hash_dev *hash, void *ctx,
+        uint16_t algo);
+typedef int (* hash_update_op_func_t)(struct hash_dev *hash, void *ctx,
+        uint16_t algo, const void *inbuf, uint32_t inlen);
+typedef int (* hash_finish_op_func_t)(struct hash_dev *hash, void *ctx,
+        uint16_t algo, void *outbuf);
+typedef bool (* hash_support_func_t)(struct hash_dev *hash, uint16_t algo);
+
+/**
+ * @struct hash_interface
+ * @brief Provides the interface into a HW hash driver
+ *
+ * @var hash_interface::start
+ * start is a hash_start_op_func_t pointer to the hashing routine used
+ * to start a new stream operation
+ *
+ * @var hash_interface::update
+ * update is a hash_update_op_func_t pointer to the hashing routine used
+ * to update the current stream operation with new data
+ *
+ * @var hash_interface::finish
+ * finish is a hash_finish_op_func_t pointer to the hashing routine used
+ * to finish the current stream operation and return a digest
+ *
+ * @var hash_interface::has_support
+ * has_support is used to inquire about which algos are natively
+ * supported
+ */
+struct hash_interface {
+    hash_start_op_func_t start;
+    hash_update_op_func_t update;
+    hash_finish_op_func_t finish;
+    hash_support_func_t has_support;
 
 Review comment:
   I would make the capabilities field a uint within struct hash_dev instead. Have an inline function to inspect it. So we ever run out of bits for capabilities, it can turned into a function.
   I think we'd end up with less text space use that way.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services