Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit d02a2e3

Browse files
committed
[[feature-random]] engine: Use libfoundation random data API.
Change all in-kernel consumers of random numbers to use MCDataCreateRandom().
1 parent b8777a3 commit d02a2e3

File tree

12 files changed

+4
-309
lines changed

12 files changed

+4
-309
lines changed

engine/Makefile.kernel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ SOURCES=\
5555
menuparse.cpp parentscript.cpp securemode.cpp \
5656
bitmapeffect.cpp bitmapeffectblur.cpp md5.cpp sha1.cpp capsule.cpp \
5757
externalv0.cpp externalv1.cpp uuid.cpp \
58-
sysspec.cpp dsklnx.cpp dskspec.cpp sysunxdate.cpp sysunxnetwork.cpp sysunxrandom.cpp \
58+
sysspec.cpp dsklnx.cpp dskspec.cpp sysunxdate.cpp sysunxnetwork.cpp \
5959
lnxpasteboard.cpp lnxtransfer.cpp lnxclipboard.cpp \
6060
lnxdc.cpp lnxdce.cpp lnxdcs.cpp lnxdclnx.cpp lnxflst.cpp lnxflstold.cpp \
6161
lnxstack.cpp lnxans.cpp \

engine/src/exec-security.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void MCSecurityEvalRandomBytes(MCExecContext& ctxt, uinteger_t p_byte_count, MCD
8383
return;
8484
}
8585

86-
if (MCU_random_bytes(p_byte_count, r_bytes))
86+
if (MCDataCreateRandom (p_byte_count, r_bytes))
8787
{
8888
ctxt.SetTheResultToEmpty();
8989
return;

engine/src/funcs.cpp

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6986,40 +6986,6 @@ char *MCHTTPProxyForURL::PACmyIpAddress(const char* const* p_arguments, unsigned
69866986

69876987
///////////////////////////////////////////////////////////////////////////////
69886988

6989-
#ifdef /* MCRandomBytes */ LEGACY_EXEC
6990-
if (byte_count->eval(ep) != ES_NORMAL && ep.ton() != ES_NORMAL)
6991-
{
6992-
MCeerror->add(EE_RANDOMBYTES_BADCOUNT, line, pos);
6993-
return ES_ERROR;
6994-
}
6995-
6996-
size_t t_count;
6997-
t_count = ep.getuint4();
6998-
6999-
// MW-2013-05-21: [[ RandomBytes ]] Updated to use system primitive, rather
7000-
// than SSL.
7001-
7002-
void *t_bytes;
7003-
t_bytes = ep . getbuffer(t_count);
7004-
if (t_bytes == nil)
7005-
{
7006-
MCeerror -> add(EE_NO_MEMORY, line, pos);
7007-
return ES_ERROR;
7008-
}
7009-
7010-
if (MCU_random_bytes(t_count, t_bytes))
7011-
ep . setlength(t_count);
7012-
else
7013-
{
7014-
ep . clear();
7015-
MCresult->copysvalue(MCString("error: could not get random bytes"));
7016-
}
7017-
7018-
return ES_NORMAL;
7019-
#endif /* MCRandomBytes */
7020-
7021-
///////////////////////////////////////////////////////////////////////////////
7022-
70236989
MCControlAtLoc::~MCControlAtLoc()
70246990
{
70256991
delete location;

engine/src/mbliphone.mm

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,18 +1163,6 @@ virtual int64_t GetFileSize(void)
11631163

11641164
//////////////////
11651165

1166-
// MW-2013-05-21: [[ RandomBytes ]] System function for random bytes on iOS.
1167-
bool MCS_random_bytes(size_t p_count, MCDataRef& r_buffer)
1168-
{
1169-
// IM-2014-04-16: [[ Bug 11860 ]] SecRandomCopyBytes returns 0 on success
1170-
MCAutoByteArray t_bytes;
1171-
return (t_bytes . New(p_count) &&
1172-
SecRandomCopyBytes(kSecRandomDefault, p_count, (uint8_t *)t_bytes . Bytes()) == 0 &&
1173-
t_bytes . CreateData(r_buffer));
1174-
}
1175-
1176-
//////////////////
1177-
11781166
extern "C" void *IOS_LoadModule(const char *name);
11791167
extern "C" void *IOS_ResolveSymbol(void *module, const char *name);
11801168

engine/src/osspec.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,6 @@ void MCS_posttourl(MCObject *p_target, MCDataRef p_data, MCStringRef p_url);
182182
void MCS_putintourl(MCObject *p_target, MCDataRef p_data, MCStringRef p_url);
183183
void MCS_geturl(MCObject *p_target, MCStringRef p_url);
184184

185-
// MW-2013-05-21: [[ RandomBytes ]] Attempt to generate a sequence of random
186-
// bytes into the provided buffer. The function returns 'false' if there isnt
187-
// enough entropy available to generate them.
188-
bool MCS_random_bytes(size_t p_count, MCDataRef& r_buffer);
189-
190185
extern uint2 MCS_getplayloudness();
191186
extern void MCS_setplayloudness(uint2 p_loudness);
192187

engine/src/srvsession.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -696,9 +696,7 @@ bool MCSessionGenerateID(MCStringRef &r_id)
696696

697697
MCAutoDataRef t_randombytes;
698698

699-
// MW-2013-05-21; [[ RandomBytes ]] Use system primitive rather than SSL
700-
// directly.
701-
/* UNCHECKED */ MCU_random_bytes(64, &t_randombytes);
699+
/* UNCHECKED */ MCDataCreateRandom (64, &t_randombytes);
702700

703701
md5_state_t t_state;
704702
md5_byte_t t_digest[16];

engine/src/sysosxrandom.cpp

Lines changed: 0 additions & 111 deletions
This file was deleted.

engine/src/sysunxrandom.cpp

Lines changed: 0 additions & 70 deletions
This file was deleted.

engine/src/sysw32random.cpp

Lines changed: 0 additions & 58 deletions
This file was deleted.

engine/src/util.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3199,15 +3199,6 @@ bool MCU_compare_strings_native(const char *p_a, bool p_a_isunicode, const char
31993199

32003200
///////////////////////////////////////////////////////////////////////////////
32013201

3202-
// MW-2013-05-21: [[ RandomBytes ]] Utility function for generating random bytes.
3203-
bool MCU_random_bytes(size_t p_bytecount, MCDataRef& r_bytes)
3204-
{
3205-
// IM-2014-08-06: [[ Bug 13038 ]] Use system implementation directly instead of SSL
3206-
return MCS_random_bytes(p_bytecount, r_bytes);
3207-
}
3208-
3209-
///////////////////////////////////////////////////////////////////////////////
3210-
32113202
#ifndef _DEBUG_MEMORY
32123203

32133204
#ifdef __VISUALC__

0 commit comments

Comments
 (0)