Skip to content

Commit 66d029d

Browse files
committed
C version re-added and made a release for it
Might be more noob friendly than a python script.
1 parent f31cbc0 commit 66d029d

File tree

22 files changed

+8597
-0
lines changed

22 files changed

+8597
-0
lines changed

LICENSE-ctrtool

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
Copyright (c) 2012 neimod
4+
Copyright (c) 2014 3DSGuy
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
SOURCES = source source/polarssl
2+
3+
CFILES := $(foreach dir, $(SOURCES), $(wildcard $(dir)/*.c))
4+
CPPFILES := $(foreach dir, $(SOURCES), $(wildcard $(dir)/*.cpp))
5+
6+
OBJS = $(CFILES:.c=.o) $(CPPFILES:.cpp=.o)
7+
8+
LIBS = -static-libstdc++ -static
9+
CXXFLAGS = -Isource
10+
CFLAGS = -std=c11 -Wall -Wextra -Os -posix -Isource -D_GNU_SOURCE
11+
OUTPUT = mkey
12+
CC = gcc
13+
14+
main: $(OBJS)
15+
g++ -o $(OUTPUT) $(LIBS) $(OBJS)
16+
17+
clean:
18+
rm -f $(OUTPUT) $(OUTPUT).exe $(OBJS)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Compatible with: 1.0-11.16 US,EU,JP,KR,TW,CN</br>
55
- Attempt to unlock your parental controls from your 3DS's System Settings until it gives you an "Inquiry Number" (chose "I forgot" twice).
66
- Next, read the rem comments in the "mkey.bat" script in a text editor for the remaining instructions, then run the same .bat script.
77
- Your masterkey should be generated, which you can use to unlock your 3DS in System Settings.
8+
Note: A windows exe is also provided in the release tab. You simply launch it and follow directions.
89

910
mkey
1011
====

source/ctr.c

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
#include <string.h>
2+
#include <stdio.h>
3+
#include <stdlib.h>
4+
5+
#include "ctr.h"
6+
7+
void ctr_set_iv( ctr_aes_context* ctx,
8+
u8 iv[16] )
9+
{
10+
memcpy(ctx->iv, iv, 16);
11+
}
12+
13+
void ctr_add_counter( ctr_aes_context* ctx,
14+
u32 carry )
15+
{
16+
u32 counter[4];
17+
u32 sum;
18+
int i;
19+
20+
for(i=0; i<4; i++)
21+
counter[i] = (ctx->ctr[i*4+0]<<24) | (ctx->ctr[i*4+1]<<16) | (ctx->ctr[i*4+2]<<8) | (ctx->ctr[i*4+3]<<0);
22+
23+
for(i=3; i>=0; i--)
24+
{
25+
sum = counter[i] + carry;
26+
27+
if (sum < counter[i])
28+
carry = 1;
29+
else
30+
carry = 0;
31+
32+
counter[i] = sum;
33+
}
34+
35+
for(i=0; i<4; i++)
36+
{
37+
ctx->ctr[i*4+0] = counter[i]>>24;
38+
ctx->ctr[i*4+1] = counter[i]>>16;
39+
ctx->ctr[i*4+2] = counter[i]>>8;
40+
ctx->ctr[i*4+3] = counter[i]>>0;
41+
}
42+
}
43+
44+
void ctr_set_counter( ctr_aes_context* ctx,
45+
u8 ctr[16] )
46+
{
47+
memcpy(ctx->ctr, ctr, 16);
48+
}
49+
50+
51+
void ctr_init_counter( ctr_aes_context* ctx,
52+
u8 key[16],
53+
u8 ctr[16] )
54+
{
55+
aes_setkey_enc(&ctx->aes, key, 128);
56+
ctr_set_counter(ctx, ctr);
57+
}
58+
59+
60+
void ctr_crypt_counter_block( ctr_aes_context* ctx,
61+
u8 input[16],
62+
u8 output[16] )
63+
{
64+
int i;
65+
u8 stream[16];
66+
67+
68+
aes_crypt_ecb(&ctx->aes, AES_ENCRYPT, ctx->ctr, stream);
69+
70+
71+
if (input)
72+
{
73+
for(i=0; i<16; i++)
74+
{
75+
output[i] = stream[i] ^ input[i];
76+
}
77+
}
78+
else
79+
{
80+
for(i=0; i<16; i++)
81+
output[i] = stream[i];
82+
}
83+
84+
ctr_add_counter(ctx, 1);
85+
}
86+
87+
88+
void ctr_crypt_counter( ctr_aes_context* ctx,
89+
u8* input,
90+
u8* output,
91+
u32 size )
92+
{
93+
u8 stream[16];
94+
u32 i;
95+
96+
while(size >= 16)
97+
{
98+
ctr_crypt_counter_block(ctx, input, output);
99+
100+
if (input)
101+
input += 16;
102+
if (output)
103+
output += 16;
104+
105+
size -= 16;
106+
}
107+
108+
if (size)
109+
{
110+
memset(stream, 0, 16);
111+
ctr_crypt_counter_block(ctx, stream, stream);
112+
113+
if (input)
114+
{
115+
for(i=0; i<size; i++)
116+
output[i] = input[i] ^ stream[i];
117+
}
118+
else
119+
{
120+
memcpy(output, stream, size);
121+
}
122+
}
123+
}
124+
125+
void ctr_init_cbc_encrypt( ctr_aes_context* ctx,
126+
u8 key[16],
127+
u8 iv[16] )
128+
{
129+
aes_setkey_enc(&ctx->aes, key, 128);
130+
ctr_set_iv(ctx, iv);
131+
}
132+
133+
void ctr_init_cbc_decrypt( ctr_aes_context* ctx,
134+
u8 key[16],
135+
u8 iv[16] )
136+
{
137+
aes_setkey_dec(&ctx->aes, key, 128);
138+
ctr_set_iv(ctx, iv);
139+
}
140+
141+
void ctr_encrypt_cbc( ctr_aes_context* ctx,
142+
u8* input,
143+
u8* output,
144+
u32 size )
145+
{
146+
aes_crypt_cbc(&ctx->aes, AES_ENCRYPT, size, ctx->iv, input, output);
147+
}
148+
149+
void ctr_decrypt_cbc( ctr_aes_context* ctx,
150+
u8* input,
151+
u8* output,
152+
u32 size )
153+
{
154+
aes_crypt_cbc(&ctx->aes, AES_DECRYPT, size, ctx->iv, input, output);
155+
}

source/ctr.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#ifndef _CTR_H
2+
#define _CTR_H
3+
4+
#include "utils.h"
5+
6+
#include "polarssl/aes.h"
7+
8+
typedef struct
9+
{
10+
u8 ctr[16];
11+
u8 iv[16];
12+
aes_context aes;
13+
} ctr_aes_context;
14+
15+
void ctr_set_iv( ctr_aes_context* ctx,
16+
u8 iv[16] );
17+
18+
void ctr_add_counter( ctr_aes_context* ctx,
19+
u32 carry );
20+
21+
void ctr_set_counter( ctr_aes_context* ctx,
22+
u8 ctr[16] );
23+
24+
25+
void ctr_init_counter( ctr_aes_context* ctx,
26+
u8 key[16],
27+
u8 ctr[16] );
28+
29+
30+
void ctr_crypt_counter_block( ctr_aes_context* ctx,
31+
u8 input[16],
32+
u8 output[16] );
33+
34+
35+
void ctr_crypt_counter( ctr_aes_context* ctx,
36+
u8* input,
37+
u8* output,
38+
u32 size );
39+
40+
41+
void ctr_init_cbc_encrypt( ctr_aes_context* ctx,
42+
u8 key[16],
43+
u8 iv[16] );
44+
45+
void ctr_init_cbc_decrypt( ctr_aes_context* ctx,
46+
u8 key[16],
47+
u8 iv[16] );
48+
49+
void ctr_encrypt_cbc( ctr_aes_context* ctx,
50+
u8* input,
51+
u8* output,
52+
u32 size );
53+
54+
void ctr_decrypt_cbc( ctr_aes_context* ctx,
55+
u8* input,
56+
u8* output,
57+
u32 size );
58+
59+
#endif

0 commit comments

Comments
 (0)