Compare commits

...

10 Commits

Author SHA1 Message Date
Agorise 3a7a71c7fd
Update LICENSE 2019-01-01 10:37:07 -06:00
Agorise bc6c083013
Update LICENSE 2018-06-17 16:31:24 +03:00
Agorise 961feef19c
Update LICENSE 2017-11-15 13:23:36 +02:00
Agorise 5113883f45 Update LICENSE 2017-10-16 13:58:51 +03:00
jmjatlanta c794c28bbe Added build targets 2017-07-17 16:13:27 -05:00
John Jones bcfc17cc93 Added comment to header 2017-02-13 09:32:55 -05:00
jmjatlanta 59e0c1ae35 minor changes, added const to some params 2016-12-15 12:41:14 -05:00
John Jones cb7be4706c added Eclipse project files 2016-11-17 16:36:56 -05:00
John Jones 4c3c2a59ed Cleaned up Makefile 2016-11-14 08:11:21 -05:00
John Jones f57e928cf8 Clean up 2016-11-10 16:28:51 -05:00
8 changed files with 145 additions and 8 deletions

73
.cproject Normal file
View File

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="cdt.managedbuild.toolchain.gnu.macosx.base.1386600442">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.macosx.base.1386600442" moduleId="org.eclipse.cdt.core.settings" name="Default">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.MachO64" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration buildProperties="" id="cdt.managedbuild.toolchain.gnu.macosx.base.1386600442" name="Default" parent="org.eclipse.cdt.build.core.emptycfg">
<folderInfo id="cdt.managedbuild.toolchain.gnu.macosx.base.1386600442.1551296983" name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.macosx.base.386985440" name="MacOSX GCC" superClass="cdt.managedbuild.toolchain.gnu.macosx.base">
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.MachO64" id="cdt.managedbuild.target.gnu.platform.macosx.base.1885573856" name="Debug Platform" osList="macosx" superClass="cdt.managedbuild.target.gnu.platform.macosx.base"/>
<builder id="cdt.managedbuild.target.gnu.builder.macosx.base.1888590002" managedBuildOn="false" name="Gnu Make Builder.Default" superClass="cdt.managedbuild.target.gnu.builder.macosx.base"/>
<tool id="cdt.managedbuild.tool.macosx.c.linker.macosx.base.203162375" name="MacOS X C Linker" superClass="cdt.managedbuild.tool.macosx.c.linker.macosx.base"/>
<tool id="cdt.managedbuild.tool.macosx.cpp.linker.macosx.base.380032459" name="MacOS X C++ Linker" superClass="cdt.managedbuild.tool.macosx.cpp.linker.macosx.base">
<inputType id="cdt.managedbuild.tool.macosx.cpp.linker.input.1178315229" superClass="cdt.managedbuild.tool.macosx.cpp.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
</inputType>
</tool>
<tool id="cdt.managedbuild.tool.gnu.assembler.macosx.base.2122297325" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.macosx.base">
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.382562785" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.archiver.macosx.base.763285879" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.macosx.base"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.macosx.base.518702814" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.macosx.base">
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.80838163" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.compiler.macosx.base.1842847648" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.macosx.base">
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1789278916" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="c-multihash.null.624575767" name="c-multihash"/>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="refreshScope"/>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets">
<buildTargets>
<target name="all" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildTarget>all</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="clean" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>clean</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
</buildTargets>
</storageModule>
</cproject>

5
.gitignore vendored
View File

@ -3,3 +3,8 @@
!.gitignore
!Makefile
!**/
*.o
*.a
.settings/language.settings.xml

27
.project Normal file
View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>c-multihash</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
</projectDescription>

View File

@ -1,6 +1,9 @@
The MIT License (MIT)
Copyright (c) 2016 Protocol Labs, Inc
Copyright (c) 2019 AGORISE, LTD.
An International Business Company, Cyprus Reg# ΗΕ375959
Also contains works from Protocol Labs, Inc. Copyright (c) 2016.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -1,6 +1,8 @@
DEBUG=true
CC = gcc
RM = rm -f
CFLAGS = -fPIC -g -O2 -std=c99 \
CFLAGS = -fPIC -O0 -std=c99 \
-Wall -Wextra -pedantic -Werror \
-Wdeclaration-after-statement \
-Wno-format-zero-length \
@ -10,10 +12,14 @@ CFLAGS = -fPIC -g -O2 -std=c99 \
-Wunused \
-Wvla
ifdef DEBUG
CFLAGS += -g3
endif
LDFLAGS = -g
LDLIBS =
TARGET_LIB = mulithash.a
TARGET_LIB = libmultihash.a
TARGET_BIN = multihash
SRCS = src/hashes.c src/errors.c src/multihash.c

View File

@ -1,3 +1,5 @@
#pragma once
#include "errors.h"
// definitions of hash functions

View File

@ -3,6 +3,27 @@
#include <stddef.h>
/**
* Functions for working with a multihash.
* A multihash is a hash with a prefix "code" that
* helps determine what type of hash this is.
* code name
* 0x00 identity
* 0x11 sha1
* 0x12 sha2-256
* 0x13 sha2-512
* 0x14 sha3-512
* 0x15 sha3-384
* 0x16 sha3-256
* 0x17 sha3-224
* 0x18 shake-128
* 0x19 shake-256
* 0x40 blake2b
* 0x41 blake2s
* # 0x0400-0x040f reserved for application specific functions
* # 0x14 formerly had the name "sha3", now deprecated
*/
/**
* returns hash code or error (which is < 0)
* @param mh the multihash
@ -26,7 +47,7 @@ int mh_multihash_length(const unsigned char *multihash, size_t len);
* @param digest the results
* @returns error if less than zero, otherwise 0
*/
int mh_multihash_digest(unsigned char *multihash, size_t len,
int mh_multihash_digest(const unsigned char *multihash, size_t len,
unsigned char **digest, size_t *digest_len);
/**
@ -44,7 +65,7 @@ int mh_new_length(int code, size_t digest_len);
* @param digest the data within the multihash
* @returns error (if < 0) or 0
*/
int mh_new(unsigned char *buffer, int code, const unsigned char *digest,
int mh_new(unsigned char* buffer, int code, const unsigned char *digest,
size_t digest_len);
#endif /* end of include guard */

View File

@ -85,14 +85,14 @@ int mh_multihash_length(const unsigned char *mh, size_t len) {
* @param digest the results
* @returns error if less than zero, otherwise 0
*/
int mh_multihash_digest(unsigned char *multihash, size_t len, unsigned char **digest,
int mh_multihash_digest(const unsigned char *multihash, size_t len, unsigned char **digest,
size_t *digest_len) {
int err = check_multihash(multihash, len);
if (err)
return err;
(*digest_len) = (size_t) mh_multihash_length(multihash, len);
(*digest) = multihash + 2; // Always true without varint
(*digest) = (unsigned char*)multihash + 2; // Always true without varint
return 0;
}
@ -117,7 +117,7 @@ int mh_new_length(int code, size_t hash_len) {
* @param digest the data within the multihash
* @returns error (if < 0) or 0
*/
int mh_new(unsigned char *buffer, int code, const unsigned char *digest,
int mh_new(unsigned char* buffer, int code, const unsigned char *digest,
size_t digest_len) {
if (code & VARINT_MASK)
return MH_E_VARINT_NOT_SUPPORTED;