Skip to content

Commit

Permalink
Merge pull request #6463 from delroth/auto-update
Browse files Browse the repository at this point in the history
Initial implementation of the Dolphin auto-updater for Windows
  • Loading branch information
Helios747 committed Mar 20, 2018
2 parents 43c92c8 + 66b41c5 commit ad8c316
Show file tree
Hide file tree
Showing 39 changed files with 7,409 additions and 4 deletions.
69 changes: 69 additions & 0 deletions Externals/ed25519/add_scalar.c
@@ -0,0 +1,69 @@
#include "ed25519.h"
#include "ge.h"
#include "sc.h"
#include "sha512.h"


/* see http://crypto.stackexchange.com/a/6215/4697 */
void ed25519_add_scalar(unsigned char *public_key, unsigned char *private_key, const unsigned char *scalar) {
const unsigned char SC_1[32] = {1}; /* scalar with value 1 */

unsigned char n[32];
ge_p3 nB;
ge_p1p1 A_p1p1;
ge_p3 A;
ge_p3 public_key_unpacked;
ge_cached T;

sha512_context hash;
unsigned char hashbuf[64];

int i;

/* copy the scalar and clear highest bit */
for (i = 0; i < 31; ++i) {
n[i] = scalar[i];
}
n[31] = scalar[31] & 127;

/* private key: a = n + t */
if (private_key) {
sc_muladd(private_key, SC_1, n, private_key);

// https://github.com/orlp/ed25519/issues/3
sha512_init(&hash);
sha512_update(&hash, private_key + 32, 32);
sha512_update(&hash, scalar, 32);
sha512_final(&hash, hashbuf);
for (i = 0; i < 32; ++i) {
private_key[32 + i] = hashbuf[i];
}
}

/* public key: A = nB + T */
if (public_key) {
/* if we know the private key we don't need a point addition, which is faster */
/* using a "timing attack" you could find out wether or not we know the private
key, but this information seems rather useless - if this is important pass
public_key and private_key seperately in 2 function calls */
if (private_key) {
ge_scalarmult_base(&A, private_key);
} else {
/* unpack public key into T */
ge_frombytes_negate_vartime(&public_key_unpacked, public_key);
fe_neg(public_key_unpacked.X, public_key_unpacked.X); /* undo negate */
fe_neg(public_key_unpacked.T, public_key_unpacked.T); /* undo negate */
ge_p3_to_cached(&T, &public_key_unpacked);

/* calculate n*B */
ge_scalarmult_base(&nB, n);

/* A = n*B + T */
ge_add(&A_p1p1, &nB, &T);
ge_p1p1_to_p3(&A, &A_p1p1);
}

/* pack public key */
ge_p3_tobytes(public_key, &A);
}
}
38 changes: 38 additions & 0 deletions Externals/ed25519/ed25519.h
@@ -0,0 +1,38 @@
#ifndef ED25519_H
#define ED25519_H

#include <stddef.h>

#if defined(_WIN32)
#if defined(ED25519_BUILD_DLL)
#define ED25519_DECLSPEC __declspec(dllexport)
#elif defined(ED25519_DLL)
#define ED25519_DECLSPEC __declspec(dllimport)
#else
#define ED25519_DECLSPEC
#endif
#else
#define ED25519_DECLSPEC
#endif


#ifdef __cplusplus
extern "C" {
#endif

#ifndef ED25519_NO_SEED
int ED25519_DECLSPEC ed25519_create_seed(unsigned char *seed);
#endif

void ED25519_DECLSPEC ed25519_create_keypair(unsigned char *public_key, unsigned char *private_key, const unsigned char *seed);
void ED25519_DECLSPEC ed25519_sign(unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key, const unsigned char *private_key);
int ED25519_DECLSPEC ed25519_verify(const unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key);
void ED25519_DECLSPEC ed25519_add_scalar(unsigned char *public_key, unsigned char *private_key, const unsigned char *scalar);
void ED25519_DECLSPEC ed25519_key_exchange(unsigned char *shared_secret, const unsigned char *public_key, const unsigned char *private_key);


#ifdef __cplusplus
}
#endif

#endif
62 changes: 62 additions & 0 deletions Externals/ed25519/ed25519.vcxproj
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="add_scalar.c" />
<ClCompile Include="fe.c" />
<ClCompile Include="ge.c" />
<ClCompile Include="keypair.c" />
<ClCompile Include="key_exchange.c" />
<ClCompile Include="sc.c" />
<ClCompile Include="seed.c" />
<ClCompile Include="sha512.c" />
<ClCompile Include="sign.c" />
<ClCompile Include="verify.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="ed25519.h" />
<ClInclude Include="fe.h" />
<ClInclude Include="fixedint.h" />
<ClInclude Include="ge.h" />
<ClInclude Include="precomp_data.h" />
<ClInclude Include="sc.h" />
<ClInclude Include="sha512.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{5BDF4B91-1491-4FB0-BC27-78E9A8E97DC3}</ProjectGuid>
<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration">
<UseDebugLibraries>true</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration">
<UseDebugLibraries>false</UseDebugLibraries>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\Source\VSProps\Base.props" />
<Import Project="..\..\Source\VSProps\ClDisableAllWarnings.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
24 changes: 24 additions & 0 deletions Externals/ed25519/ed25519.vcxproj.filters
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="add_scalar.c" />
<ClCompile Include="fe.c" />
<ClCompile Include="ge.c" />
<ClCompile Include="key_exchange.c" />
<ClCompile Include="keypair.c" />
<ClCompile Include="sc.c" />
<ClCompile Include="seed.c" />
<ClCompile Include="sha512.c" />
<ClCompile Include="sign.c" />
<ClCompile Include="verify.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="ed25519.h" />
<ClInclude Include="fe.h" />
<ClInclude Include="fixedint.h" />
<ClInclude Include="ge.h" />
<ClInclude Include="precomp_data.h" />
<ClInclude Include="sc.h" />
<ClInclude Include="sha512.h" />
</ItemGroup>
</Project>

0 comments on commit ad8c316

Please sign in to comment.