Program Listing for File sha256.h

Return to documentation for file (include/rcutils/sha256.h)

// Copyright 2023 Open Source Robotics Foundation, Inc.
//
// Licensed 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 RCUTILS__SHA256_H_
#define RCUTILS__SHA256_H_

#ifdef __cplusplus
extern "C"
{
#endif

#include <stddef.h>
#include <stdint.h>

#include "rcutils/visibility_control.h"

#define RCUTILS_SHA256_BLOCK_SIZE 32

typedef struct RCUTILS_PUBLIC_TYPE rcutils_sha256_ctx_s
{
  uint8_t data[64];
  size_t datalen;
  uint64_t bitlen;
  uint32_t state[8];
} rcutils_sha256_ctx_t;


RCUTILS_PUBLIC
void rcutils_sha256_init(rcutils_sha256_ctx_t * ctx);


RCUTILS_PUBLIC
void rcutils_sha256_update(rcutils_sha256_ctx_t * ctx, const uint8_t * data, size_t data_len);


#ifdef DOXYGEN_ONLY
// One of the tools used by rosdoc2 misunderstands uint8_t[] as a uint8_t,
// so make it a pointer for documentation purposes.
RCUTILS_PUBLIC
void rcutils_sha256_final(
  rcutils_sha256_ctx_t * ctx,
  uint8_t * output_hash);
#else
RCUTILS_PUBLIC
void rcutils_sha256_final(
  rcutils_sha256_ctx_t * ctx,
  uint8_t output_hash[RCUTILS_SHA256_BLOCK_SIZE]);
#endif

#ifdef __cplusplus
}
#endif

#endif  // RCUTILS__SHA256_H_